Here is the code that I'm trying to use to set a dropdownlist's data source at run time. It doesn't seem to work for the data source.
Thanks in advance.
Ken
...
protected DataTable tbl1;
protected DataTable tbl2;
protected DataTab;e tbl3;
...
private void XXX_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.DataSetIndex >= 0)
{
//
// Column 1 is a template column whose ItemTemplate contains a
// DropDownList control. We want the selection list of the
// DropDownList on each row to be one of three possible lists,
// as determimed by the text in bound column #13 of that row.
//
DataGridItem dgi = (DataGridItem)e.Item;
DropDownList dd = (DropDownList)dgi.Cells[1].Controls[1];
string codeType = dgi.Cells[13].Text;
if (codeType.Equals("S"))
{
dd.DataSource = tbl1;
dd.DataBind();
}
if (codeType.Equals("A"))
{
dd.DataSource = tbl2;
dd.DataBind();
}
if (codeType.Equals("X"))
{
dd.DataSource = tbl3;
dd.DataBind();
}
//
// In spite of setting the DataSource property and
// calling DataBind(), the list remains unchanged
// from what was specified at design-time. However,
// setting other properties, such as BackColor,
// for instance, works fine.
//
}
}
Thanks in advance.
Ken
...
protected DataTable tbl1;
protected DataTable tbl2;
protected DataTab;e tbl3;
...
private void XXX_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.DataSetIndex >= 0)
{
//
// Column 1 is a template column whose ItemTemplate contains a
// DropDownList control. We want the selection list of the
// DropDownList on each row to be one of three possible lists,
// as determimed by the text in bound column #13 of that row.
//
DataGridItem dgi = (DataGridItem)e.Item;
DropDownList dd = (DropDownList)dgi.Cells[1].Controls[1];
string codeType = dgi.Cells[13].Text;
if (codeType.Equals("S"))
{
dd.DataSource = tbl1;
dd.DataBind();
}
if (codeType.Equals("A"))
{
dd.DataSource = tbl2;
dd.DataBind();
}
if (codeType.Equals("X"))
{
dd.DataSource = tbl3;
dd.DataBind();
}
//
// In spite of setting the DataSource property and
// calling DataBind(), the list remains unchanged
// from what was specified at design-time. However,
// setting other properties, such as BackColor,
// for instance, works fine.
//
}
}