Building Dynamic Controls

Discussion in 'ASP .Net Building Controls' started by Robert Bevington, Jul 11, 2007.

  1. Hi everyone,
    Can anyone point me in the right direction on this one?

    I have a page with a GridView whose column names vary. On Page Load I
    search for specific columns (they can be identified by a prefix in the
    column name) and then want to create one or more drop-down list boxes
    depending on the number of columns. Each drop-down list box is to be
    associated to a column. The number and names of the columns is not fixed.

    What's the best approach for dealing with this?

    I'm trying a For Next Loop at the moment but cannot get the dynamic bits
    working. I get three drop-down lists.

    <%-- Start Dynamic attribute field creation--%>

    <% For attCount = 1 To ATT_Columns.Count
    Dim ATT_Name As String = ATT_Columns(attCount)
    %>

    <asp:DropDownList ID="cboDept" runat="server"
    DataSourceID="SqlDataSource1" DataTextField="ATT_Department"
    DataValueField="ATT_Department" AppendDataBoundItems="True">

    <asp:ListItem>Select from list</asp:ListItem>
    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:Search4TextConnectionString %>"

    SelectCommand="SELECT DISTINCT [ATT_Department] FROM NewTM2 ORDER BY
    ATT_Department"></asp:SqlDataSource>
    <% Next
    %>

    How can I replace, for example, ATT_Department with the variable ATT_Name

    Any help would be great.

    Thanks

    Rob
     
    Robert Bevington, Jul 11, 2007
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.