D
Dave
Why doesn't this work?
My webpage changes databound items in a dropdown list depending on
what form the user selects. And the page needs to remember what the
user selected, and reselect the dropdown items between posts (using
selectedValue).
The problem is I get the above "does not exist" error when the user
switches forms because of the list changing.
So, I was trying to make a function search for the text in the list
and return a default value (or null) if necessary.
Here is the list:
<asp:dropdownlist SelectedValue='<%# rFolding() %>' ID="tFolding"
runat="Server" cssclass="formfield" datasourceid="ListFoldingSource"
DataTextField="Item" DataValueField="Item"/></td>
And the relevant function looks something like this:
String rFolding()
{
String rtn = ...read from database...
// Look for the string in the list
ListItem lstitem = tFolding.Items.FindByText(rtn);
if (lstitem == null) rtn = "(Select)"; // if not found,
"(Select)" is in every dropdown list so use it
return rtn;
}
This halfway works, but I'm still getting the error when the user
switches forms and the list items change. I expected this technique
to avoid ever getting: "SelectedValue which is invalid because it does
not exist in the list of items." Did I make some silly mistake or is
there an overall problem? Why doesn't this work?
My webpage changes databound items in a dropdown list depending on
what form the user selects. And the page needs to remember what the
user selected, and reselect the dropdown items between posts (using
selectedValue).
The problem is I get the above "does not exist" error when the user
switches forms because of the list changing.
So, I was trying to make a function search for the text in the list
and return a default value (or null) if necessary.
Here is the list:
<asp:dropdownlist SelectedValue='<%# rFolding() %>' ID="tFolding"
runat="Server" cssclass="formfield" datasourceid="ListFoldingSource"
DataTextField="Item" DataValueField="Item"/></td>
And the relevant function looks something like this:
String rFolding()
{
String rtn = ...read from database...
// Look for the string in the list
ListItem lstitem = tFolding.Items.FindByText(rtn);
if (lstitem == null) rtn = "(Select)"; // if not found,
"(Select)" is in every dropdown list so use it
return rtn;
}
This halfway works, but I'm still getting the error when the user
switches forms and the list items change. I expected this technique
to avoid ever getting: "SelectedValue which is invalid because it does
not exist in the list of items." Did I make some silly mistake or is
there an overall problem? Why doesn't this work?