J
jjack100
I have a DropDownList that is nested inside a Repeater. The datasource
of the DropDownList is declared in the aspx, not the codebehind. So we
have this:
<asp:Repeater ID="rptOptions" runat="server">
<ItemTemplate>
<%# Eval("option_name") %>
<aspropDownList ID="dlOptions" runat="server"
DataSource='<%#
GetOptionValuesDL((int)DataBinder.Eval(Container.DataItem,
"Item_ID"))%>'
DataTextField="option_display" DataValueField="option_value_id">
</aspropDownList>
</ItemTemplate>
</asp:Repeater>
Then in the codebehind we have the function GetOptionValuesDL which
returns a SqlDataReader which is databound to the DropDownList:
protected SqlDataReader GetOptionValuesDL(int intItemID)
{
ProductsDB options = new ProductsDB();
SqlDataReader dr = options.GetOptionValues(intItemID);
return dr;
}
That works. But now I want to insert a listitem as the default in each
created dropdown. Since this has to be done after the dropdownlists are
bound, where can I do it? I got close with the PreRender event of the
DropDownLists:
protected void dlOptions_PreRender(object sender, System.EventArgs e)
{
DropDownList dlClone =
(DropDownList)rptOptions.Items[0].FindControl("dlOptions");
dlClone.Items.Insert(0, "Select");
}
The problem: this obviously only works for the first created
DropDownList (Items[0]) -- I haven't been able to come up with a way to
programmatically find each DropDownList in this manner.
Any ideas?
Thanks
Jack
of the DropDownList is declared in the aspx, not the codebehind. So we
have this:
<asp:Repeater ID="rptOptions" runat="server">
<ItemTemplate>
<%# Eval("option_name") %>
<aspropDownList ID="dlOptions" runat="server"
DataSource='<%#
GetOptionValuesDL((int)DataBinder.Eval(Container.DataItem,
"Item_ID"))%>'
DataTextField="option_display" DataValueField="option_value_id">
</aspropDownList>
</ItemTemplate>
</asp:Repeater>
Then in the codebehind we have the function GetOptionValuesDL which
returns a SqlDataReader which is databound to the DropDownList:
protected SqlDataReader GetOptionValuesDL(int intItemID)
{
ProductsDB options = new ProductsDB();
SqlDataReader dr = options.GetOptionValues(intItemID);
return dr;
}
That works. But now I want to insert a listitem as the default in each
created dropdown. Since this has to be done after the dropdownlists are
bound, where can I do it? I got close with the PreRender event of the
DropDownLists:
protected void dlOptions_PreRender(object sender, System.EventArgs e)
{
DropDownList dlClone =
(DropDownList)rptOptions.Items[0].FindControl("dlOptions");
dlClone.Items.Insert(0, "Select");
}
The problem: this obviously only works for the first created
DropDownList (Items[0]) -- I haven't been able to come up with a way to
programmatically find each DropDownList in this manner.
Any ideas?
Thanks
Jack