DropDown

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#
 
M

Milosz Skalecki [MCAD]

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());
}
}
}
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top