[thelist] ASP.NET dropdownlist error
Joel D Canfield
joel at streamliine.com
Tue Sep 25 18:07:05 CDT 2007
I'm trying to create a form to edit info in the SQL 2005 database. The
code below gives me the error
'DeptDDL' has a SelectedValue which is invalid because
it does not exist in the list of items.
Parameter name: value
when I click the automatically created 'Edit' button/link.
The SQL query *does* return valid results, one of which matches
*exactly* (no funky spaces or anything) the existing value in this row
of data.
<asp:SqlDataSource
ID="srcDepts" runat="server"
ConnectionString="<%$ ConnectionStrings:cnxHelm %>"
SelectCommand="SELECT id, DeptName FROM Departments ORDER BY
DeptName">
</asp:SqlDataSource>
<asp:TemplateField HeaderText="Dept" SortExpression="DeptName">
<ItemTemplate>
<%# Eval("DeptName") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="DeptDDL" runat="server"
DataSourceID="srcDepts"
DataTextField="DeptName"
DataValueField="id"
AppendDataBoundItems="True"
SelectedValue='<%# Bind("DeptName") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
Thoughts?
joel
More information about the thelist
mailing list