Code for Composite web part(A dropdown will have initial value of list and on selecting value will show List)

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace GriddView.CompositeWebPart
{
    [ToolboxItemAttribute(false)]
    public class CompositeWebPart : WebPart
    {
        private DropDownList listdropdown;
        private GridView Itemgridview;
        protected override void CreateChildControls()
        {
            listdropdown = new DropDownList();
            listdropdown.AutoPostBack = true;
            listdropdown.SelectedIndexChanged += new EventHandler(listdropdown_SelectedIndexChanged);
            Controls.Add(listdropdown);
          
            Controls.Add(new LiteralControl("<br/><br/>"));
            Itemgridview = new GridView();
            Controls.Add(Itemgridview);


        }
        protected void listdropdown_SelectedIndexChanged(object sender,EventArgs e)
        {
            var web = SPContext.Current.Web;
            var list = web.Lists[listdropdown.Text];
            var items = list.Items.GetDataTable();
            Itemgridview.DataSource = items;
            Itemgridview.DataBind();
        }
        protected override void OnPreRender(EventArgs e)
        {
            if (Page.IsPostBack) return;
            EnsureChildControls();
            var web = SPContext.Current.Web;
            listdropdown.DataSource = SPContext.Current.Web.Lists;
            listdropdown.DataTextField = "Title";
            listdropdown.DataBind();
        }
    }
}

Comments

Popular posts from this blog

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

How to add custom filter lookup field based on OptionSet field selection in Dynamics CRM.

go to top image