Building Dynamic Controls

R

Robert Bevington

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top