[thelist] ASP.NET dropdownlist error

Anthony Baratta anthony at baratta.com
Wed Sep 26 00:22:38 CDT 2007


Joel I don't believe you can mix inline code with web-controls. What you 
want to do instead is have a code block that sets all this info outside 
of the web control:

srcDepts.ConnectionString = ConnectionStrings:cnxHelm;
DeptDDL.SelectedValue = Bind("DeptName")

P.S. What is the output of Bind("DeptName")?? Is that a function?



Joel D Canfield wrote:
> 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