Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frends,

There is issue related to SharePoint server. Actually my issue is that. I added one empty project of SharePoint 2010 in VS 2010 and add a application page. In application page.aspx.cs I write the code for a grid view. and I create a List in SharePoint Server 2010 there are some columns suppose "Name" and these values is AbC. CSE etc.

Then my issue is that, I Want to show the" values of 'Name' Column of List" in Grid View. when we run the program, So what code I write in Application page.

Example : My list Name is "MyList" there is one Name Column and some values is there
and in added a grid view code in app page.
when deploy the page the Name values shows is Grid View.

A lot of Thnx,
Sumit Magician.
[no name] 7-Nov-11 14:10pm    
What have you tried so far? Why are you writing an application page and not using a list view Web part?
sumitmagician 8-Nov-11 0:16am    
This is my requirement that I used application page.

1 solution

Hi Sumit,

Here I'm giving you the code for access your sharepoint list and the retrive data. You have to add the retrieved data to the data grid.

//SPSite object
SPSite oSpSite = new SPSite("http://spserver:2222/");// Your server

// Create SPWeb Object to open the Web.
//Connect to the web using SPWeb object
SPWeb oSPWeb = oSpSite.OpenWeb();

// Create SPList object to access the List.
//Here we need to pass List Name which we want to access from Sharepoint site.
//List Object to get the list from a sharepoint site
SPList oSpList = oSPWeb.Lists["MyList"];

//Create SPListItemCollection to get all the list items.
//Item Collection Object getting all the items form the list
SPListItemCollection oSpListCln = oSpList.Items;

//Iterate through each and every item in the ItemCollection object.
//iterate through all the items in itemcollection object
foreach (SPListItem item in oSpListCln)
string name =item["Name"];

//In here write a code for add the list data values to the Gridview

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900