R
Robert Bevington
Hi everyone,
I've rewritten this one as I think I confused everyone last time :-(
I'm trying to create dropdown lists that a user can select in order to
filter the data in a gridview. My main problem is the number and names
of the dropdown lists have to be created at runtime.
Creating the dropdowns is easy via a simple VB loop round some ASP code.
But how do I populate the dropdowns with the required data?
When the loop starts the value of the dropdown's datatextfield is "". I
then set it to the variable ATT_Name. Works fine if I only have one
loop. However, on the second loop when I try to set the dropdown's
datatextfield to the new value of ATT_Name, I get an error message that
the datarowview does not contain the property "<value of ATT_Name>".
Do I have to reset the property somehow?
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>
<aspropDownList ID="cbo1" runat="server"
DataSourceID="SqlDataSource1" AppendDataBoundItems="True">
</aspropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Search4TextConnectionString %>">
</asp:SqlDataSource>
</td>
</tr>
<%
Next
%>
Best regards,
Robert
I've rewritten this one as I think I confused everyone last time :-(
I'm trying to create dropdown lists that a user can select in order to
filter the data in a gridview. My main problem is the number and names
of the dropdown lists have to be created at runtime.
Creating the dropdowns is easy via a simple VB loop round some ASP code.
But how do I populate the dropdowns with the required data?
When the loop starts the value of the dropdown's datatextfield is "". I
then set it to the variable ATT_Name. Works fine if I only have one
loop. However, on the second loop when I try to set the dropdown's
datatextfield to the new value of ATT_Name, I get an error message that
the datarowview does not contain the property "<value of ATT_Name>".
Do I have to reset the property somehow?
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>
<aspropDownList ID="cbo1" runat="server"
DataSourceID="SqlDataSource1" AppendDataBoundItems="True">
</aspropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Search4TextConnectionString %>">
</asp:SqlDataSource>
</td>
</tr>
<%
Next
%>
Best regards,
Robert