views:

165

answers:

1

We are using SharePoint 2010 Foundation.

We have an item in a list that is a dropdown with values from another list.

When we access the list as a SharePoint list it works fine, we can select a value, save the list, the next time we access the list the correct value is selected.

We have programmed a form that will updated the list. When we pull up the form, select a value and save it, we can see by accessing the list directly that the value has been saved.

However, when we pull up the form again it is the first item in the list that is selected. Have tried storing the selected value is a temp variable before binding the list but have not been able to get it to work. Anyone know how to fix this?

A: 

We found a solution.

The trick was to get the number that is the first part of the ToString of the SPListItem, before binding the list.

Then use that number to set the selected value after the list is bound

Parameters:

 SPListItem currentItem, string fieldName

Code:

 string selectedValue = currentItem[fieldName].ToString().Substring(0,1);

 //... Bind list

 ddlLookup.SelectedValue = selectedValue;
Shiraz Bhaiji
If this is your answer, mark it as such so this does not show up in the "unanswered" feed.
CBono
@CBono, I will, but the system does not allow you to accept your own answer before x days has elapsed.
Shiraz Bhaiji