Monday, December 5, 2011

Display List Data with SPGridView

Steps:
1. Drag and drop SPGridView and SPDataSource from toolbox. (If you dont have them, right click on tabs and click on choose items and select GridView and SPDatasource).

2. Write the following in Code Behind for binding SPGridView with List Data.

protected void Page_Load(object sender, EventArgs e)
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
SPList List = myWeb.Lists["Mylist"];
SPDataSource1.List = List ;
GridView .DataSource = SPDataSource1;
GridView .DataBind();
}

No comments:

Post a Comment