DropDown

  • Thread starter Thread starter Paulo
  • Start date Start date
P

Paulo

Hi, I have a DropDown (ComboBox) control on a grid template field.

How do I do a loop from 1 to 50 to feed this combo with these numbers? How
do I capture the name of the control? at what moment? should it be used
inside some grid event?

Can you help me? Many thanks!

VS 2005 - Asp.net 2.0 C#
 
Howdy Paulo,

Please find example below.

<asp:GridView runat="server" ID="gv" AutoGenerateColumns="false"
onrowdatabound="gv_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList runat="server" ID="ddl">
<asp:ListItem Text="Please select..." Value="" />
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

C# Code behind:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gv.DataSource = new int[10];
gv.DataBind();
}
}
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddl");

for (int i = 0; i < 50; i++)
{
ddl.Items.Add(i.ToString());
}
}
}
 
Back
Top