3

I have a sharepoint list named Products with the following columns:

  • ProductID
  • Name
  • Price.

In ASPX page there are 3 text boxes that will hold the data for each corresponding column as shown below:

textbox1 = productID

textbox2 = Name

textbox3 = Price

The list has 3 products registered with appropriate data. The text boxes in the ASPX page should be populated with data for each product. The data has to be retrieved from the list and bound to the text box using C#.

2 Answers 2

2

Use the following code to get all items from the list. Once you have the ListItemCollection, you can access value of each list item and bind it to the text box.

 SPWeb web = SPContext.Current.Web;
 SPList docList = web.Lists.GetList(enter list ID here, true);
 SPListItemCollection items = docList.GetItems();
 foreach(SPItem item in items)
 {
     textbox1.text = item.ID;
     textbox1.text = item["Name"];
     textbox1.text = item["Price"]; 
 }      
7
  • where can i get list ID @Mancy Commented Nov 2, 2015 at 10:10
  • Please refer to my answer here - sharepoint.stackexchange.com/questions/161186/…, you will be able to get List Id. Commented Nov 2, 2015 at 11:09
  • 1
    something is not going well, i have 3 product on the list witth the following info: ID: 1 Name: Mouse Price: 6 ID: 2 Name: Keyboard Price: 7 ID: 3 Name: Hardrive Price: 50 if textbox1 contain id 1 i want textbox2 to show mouse and textbox 3 to show 6, else if textbox1 contain id 2 i want textbox2 to show keyboardand textbox 3 to show 7, and so on... Commented Nov 3, 2015 at 8:54
  • I understand this. In order to implement this you would need to have a dropdown for the IDs. As per the selection of the ID you can display the relevant price and product name. Commented Nov 3, 2015 at 9:07
  • 1
    Do you mean to say that you want the single text box to display value for Id: 1 ,2 ,3? Commented Nov 3, 2015 at 9:40
3

You can retrieve the SharePoint list data using client-object model in ASPX page very easily. here is the link to Access SharePoint list data using Client Object Model

2
  • Helpful answer.. Commented Nov 2, 2015 at 9:31
  • 3
    Please always share some code snippet if you are pointing to an external link.
    – Taran Goel
    Commented Nov 2, 2015 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.