Copy the following between the tags of the aspx page in HTML view.
Copy the following in the Page_Load method in code-behind or
between the tags
private void Page_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable();
DataRow dr;
DropDownList ddl;
int i;
//Create the datasource for the datagrid
dt.Columns.Add("col1", Type.GetType("System.String"));
for(i = 0; i < 5; i++)
{
dr = dt.NewRow();
dr[0] = i.ToString();
dt.Rows.Add(dr);
}
//bind datasource to the datagrid
dgtest.DataSource = dt;
dgtest.DataBind();
//manipulate the drop-down list of each row of the datagrid.
//this code simply displays the ID as the sole element of the drop-down.
for(i = 0; i < dgtest.Items.Count; i++)
{
ddl = (DropDownList)dgtest.Items[i].FindControl("ddltest");
if(ddl != null)
{
ddl.Items.Clear();
ddl.Items.Add(i.ToString());
}
}
}
output:
ID ¦
-------------------
0 ¦ | 0 |v|
1 ¦ | 1 |v|
2 ¦ | 2 |v|
3 ¦ | 3 |v|
4 ¦ | 4 |v|