[thelist] ASP.NET dropdownlist error

Joel D Canfield joel at streamliine.com
Wed Sep 26 02:17:36 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:

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:

            ID="srcDepts" runat="server" 
            ConnectionString="<%$ ConnectionStrings:cnxHelm %>"
            SelectCommand="SELECT DeptName FROM Departments ORDER BY
        <asp:TemplateField HeaderText="Dept" SortExpression="DeptName">
                <%# Eval("DeptName") %>
                    ID="DeptDDL" runat="server" 
                    SelectedValue='<%# Bind("DeptName") %>' >

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.


More information about the thelist mailing list