[thelist] ASP.NET dropdownlist error

rahaman rahaman29 at gmail.com
Wed Sep 26 03:30:31 CDT 2007

modify your query as to select dept id too

*SELECT DeptId,DeptName FROM Departments ORDER BY DeptId
On 9/26/07, Joel D Canfield <joel at streamliine.com> wrote:
> > 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:
> Hmm. I don't understand exactly where that's happening. The code I've
> got is a direct copy from Walther's ASP.NET, with only the names of the
> db fields and the IDs of the bits changed. That doesn't mean it's right;
> I really don't know how all this works yet so on those rare instances
> where it does, I'm sure I have the same look on my face Dr. Frankenstein
> did when the monster opened its eyes.
> > P.S. What is the output of Bind("DeptName")?? Is that a function?
> Bind("DeptName") *should* be the field 'DeptName' from the query in the
> data source this dropdownlist is getting data from.
> Rummaging a bit more, *this* works, but it uses the department name as
> the identifier in the dropdownlist, where I'd prefer to use the
> department id:
>        <asp:SqlDataSource
>            ID="srcDepts" runat="server"
>            ConnectionString="<%$ ConnectionStrings:cnxHelm %>"
>            SelectCommand="SELECT 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="DeptName"
>                    AppendDataBoundItems="True"
>                    SelectedValue='<%# Bind("DeptName") %>' >
>                </asp:DropDownList>
>            </EditItemTemplate>
>        </asp:TemplateField>
> So - when I include 'id' in the SQL for the datasource, and include it
> as the DataValueField in the DDL (and whether or not it's included in
> the SQL for the row of data being modified) I get the error.
> I see a lotta great things with .NET, especially 2.0, but it's maddening
> to spend six hours creating a db-populated select that I could have done
> in 90 seconds in classic ASP.
> Thanks again for any pointers on how I get this to let me use the
> Departments.id in the DDL.
> joel
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

More information about the thelist mailing list