Creating Dynamic Controls

R

Robert Bevington

Hi everyone,

I have one problem, but when I solve the one, another appears:

I've written a loop that creates a variable number of dropdownlist
controls. When I load the page, the required number of dropdowns appear
on the page, but they contain the entry System.Data.DataRowView and the
not the actual data. In the first control this appears once, in the
second control there are two items and the third three.

How do I get the control to show the required data?

When I had no loop, the dropdown showed the correct data as the 2 lines:

'Me.cbo1.DataTextField = ATT_Name
'Me.cbo1.DataValueField = ATT_Name

were not commented out. However if I leave them in the loop code, on the
second time through the loop (when attcount 2), I get an error message
on the lines of "DataBinding: System.Data.DataRowView contains no
property called ATT_DocType".

where ATT_DocType the second value for ATT_Name is.
Me.cbo1.DataTextfield is still set to the first value of ATT_Name

What am I doing wrong?

Here's my loop snippet:

-- Start dynamic attribute field creation--%>
<%
For attCount = 1 To ATT_Columns.Count
%>
<tr>
<%
'Full name of attribute fields for SQL command
ATT_Name = ATT_Columns(attCount)
'Display name for label of drop-down list
Me.Label1.Text = ATT_Name.Substring(4, (ATT_Name.Length - 4)) & ":"

'Me.cbo1.DataTextField = ATT_Name
'Me.cbo1.DataValueField = ATT_Name

Me.SqlDataSource1.SelectCommand = "SELECT DISTINCT " & ATT_Name &
" FROM " & Me.lblTableName.Text & " ORDER BY " & ATT_Name & ""
%>
<td>

<asp:Label ID="Label1" runat="server" Text=""> </asp:Label>
</td>
<td>
<asp:DropDownList ID="cbo1" runat="server"
DataSourceID="SqlDataSource1" AppendDataBoundItems="True">
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Search4TextConnectionString %>">
</asp:SqlDataSource>
</td>
</tr>

<%
Next
%>

Thanks for any help

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

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top