Visit our SharePoint Forum

SharePoint developer? Submit Yourself as Freelancer

Tuesday, May 27, 2008

Display List Data with SPGridView

See Detail example at Using SPGridView to display list Data WebPart

Topic Covers :
1. How to 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();
}

See Detail example at Using SPGridView to display list Data WebPart

5 comments:

Anonymous said...

Hi,

where do I find SPGridView and SPDataSource to add them to my toobox ?

Thanks

Isha kapoor said...

Add Microsoft.sharepoint.dll in the refrence section in the project.
Now in right click in tools under general tab(any tab)and select choose items. Then select SPGridView and SPDataSource libraries and they will be added along with your other.net tools.
If you are using Class library project then create a instance of SPGridView with new keyword

Alex Talarico said...

"create a instance of SPGridView with new keyword" hehe - well said ;)

Anonymous said...

this is rubbish. explain yourself and stop waisting everyones time.

Anonymous said...

If the "new" keyword is confusing to you, please read up on C# fundamentals. You will need to either add the SPGridView XML definition to the *.aspx document in your project, or instantiate an SPGridView in C# in the *.aspx.cs document.

SharePoint Programming