Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Binding problem

Status
Not open for further replies.

KENDIGIT

Programmer
Mar 26, 2003
17
0
0
US
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.
//
}
}
 
Solved the problem. In the Form, do not place any custom
binding expressions. You have to do them all from the code behind.
This was solved by the folks at Microsoft.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top