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
    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(new LiteralControl("<br/><br/>"));
            Itemgridview = new GridView();

        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;
        protected override void OnPreRender(EventArgs e)
            if (Page.IsPostBack) return;
            var web = SPContext.Current.Web;
            listdropdown.DataSource = SPContext.Current.Web.Lists;
            listdropdown.DataTextField = "Title";


Popular posts from this blog

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

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

Dumps for Microsoft Dynamics CRM MB2-703 Practice Exam Questions Free

How to import CSV files into DataTable in C#

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

go to top image