Shalvin Interests

Tuesday, November 10, 2015

SharePoint Filling a GridView with List Information based on the DropDownList Selection


protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
            SPSite site = new SPSite("http://abc-pc");

            SPWeb web = site.RootWeb;

           
            DropDownList1.DataSource = web.Lists;
            DropDownList1.DataTextField = "Title";
            DropDownList1.DataBind();
            
    }
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
     SPSite site = new SPSite("http://abc-pc");

     SPWeb web = site.RootWeb;
     SPList list = web.Lists[DropDownList1.Text];
          
     var item = list.Items;
     GridView1.DataSource = item.GetDataTable();
     GridView1.DataBind();
}

No comments:

Post a Comment