DropDownList Datagrid issues

  • Thread starter msingh.russelmetals
  • Start date
M

msingh.russelmetals

Hello everybody.

I have a DropDownList in my Datagrid.
The DropDownList is prepopulated with data.

I'm capturing the event OnItemDataBound, and as the rows are populated
I'm selecting the correct index in my DropDownList based on a value for
that row.

My issue is that it seems that instead of selecting the value in the
DropDownList for that row, it selects the value in all the
DropDownLists for that column in the entire DataGrid.

So all the rows have the same value selected in the DropDownList that
corresponds to the value of the item that was meant for the last row.

Anybody seen this before and can help me out?

Thanks in advanced.
 
D

DomNewbie

This is how I do it, though there may be a more elegant solution...

private void
DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//select the data from the datasource
DataRow[] drs =td.Stock.Select("rowGuide=" +
e.Item.Cells[2].Text);
//select the DropDownlist control you're looking at (Control 1 in cell
10)
DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
//set the dropdownlist to reflect the data
ddl.SelectedValue =drs[0]["InStock"].ToString();

}
 
D

DomNewbie

This is how I do it, though there may be a more elegant solution...

private void
DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//select the data from the datasource
DataRow[] drs =td.Stock.Select("rowGuide=" +
e.Item.Cells[2].Text);
//select the DropDownlist control you're looking at (Control 1 in cell
10)
DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
//set the dropdownlist to reflect the data
ddl.SelectedValue =drs[0]["InStock"].ToString();

}
 
D

DomNewbie

This is how I do it, though there may be a more elegant solution...

private void
DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//select the data from the datasource
DataRow[] drs =td.Stock.Select("rowGuide=" +
e.Item.Cells[2].Text);
//select the DropDownlist control you're looking at (Control 1 in cell
10)
DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
//set the dropdownlist to reflect the data
ddl.SelectedValue =drs[0]["InStock"].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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top