Hi
I have a aspx application written in c#.
I have created a datagrid control on the page.
One of the columns in the control is a dropdownlist.
I would like to set the data source of the dropdownlist to a different
recordset for each row.
How can I do this in C#?
I have used the ItemDataBound event, to set the DataSource for each row
of the dropdownlist.
Running the code in debug mode, I can see that the DataSource is being
reset, however, when my page comes up, there are two rows in the data
grid, both drop down lists have the same data source.
private void dgInvoiceList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e )
{
DropDownList ddlCategory =
(DropDownList)e.Item.FindControl("ddlCategory");
switch ((int)(e.Item.ItemType))
{ {
case (int)ListItemType.Item :
if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;
case (int)ListItemType.AlternatingItem:
if( (e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtentionExpense) |
(e.Item.Cells[13].Text ==
GTS.Common.GTSConsts.CostCategoryTypeCode_BookingE xtensionInternalAir)
)
{
ddlCategory.DataSource = mdsCostCategories_Extensions.Tables[0];
ddlCategory.DataBind();
}
break;
}
}