M
marcbb
Hi all,
I have a really strange problem working with Dropdownlists in a
DataGrid.
I'm trying to preselect some values from the DropDownlist for each
row in the DataGrid, but it seems that both selectedIndex has the same
reference and modifying the first one also automatically modify the
second one. For example:
A <DDL_1> <DDL_2>
B <DDL_1> <DDL_2>
... ... ...
For each row (i) in the DataGrid, I make:
[1]
//Get Dropdownlist 1
DropDownList ddl1 = (DropDownList)
dgList.Items.FindControl("DDL_1");
//Get Dropdownlist 2
DropDownList ddl2 = (DropDownList)
dgList.Items.FindControl("DDL_2");
and then, I preselect their SelectedIndex:
[2] I have this function for this:
public void SelectDropDownValue(DropDownList ddl, string
selectedValue)
{
ListItem li = null;
li = ddl.Items.FindByValue(selectedValue);
if (li != null)
{
int index = ddl.Items.IndexOf(li);
ddl.SelectedIndex = index;
}
}
when I make:
//here, ddl1.SelectedIndex = 0 and ddl2.SelectedIndex = 0
SelectDropDownValue(ddl1, val1); //after this, ddl1.SelectedIndex =
val1 and ddl2.SelectedIndex = 0
SelectDropDownValue(ddl2, val2); //after this, ddl1.SelectedIndex
= val2 and ddl2.SelectedIndex = val2
//after this, every change that i make to ddl1.SelectedIndex is also
affecting at the same time to ddl2.SelectedIndex and IDEM with
VICEVERSA.
Is it normal?
Thanks in advance
I have a really strange problem working with Dropdownlists in a
DataGrid.
I'm trying to preselect some values from the DropDownlist for each
row in the DataGrid, but it seems that both selectedIndex has the same
reference and modifying the first one also automatically modify the
second one. For example:
A <DDL_1> <DDL_2>
B <DDL_1> <DDL_2>
... ... ...
For each row (i) in the DataGrid, I make:
[1]
//Get Dropdownlist 1
DropDownList ddl1 = (DropDownList)
dgList.Items.FindControl("DDL_1");
//Get Dropdownlist 2
DropDownList ddl2 = (DropDownList)
dgList.Items.FindControl("DDL_2");
and then, I preselect their SelectedIndex:
[2] I have this function for this:
public void SelectDropDownValue(DropDownList ddl, string
selectedValue)
{
ListItem li = null;
li = ddl.Items.FindByValue(selectedValue);
if (li != null)
{
int index = ddl.Items.IndexOf(li);
ddl.SelectedIndex = index;
}
}
when I make:
//here, ddl1.SelectedIndex = 0 and ddl2.SelectedIndex = 0
SelectDropDownValue(ddl1, val1); //after this, ddl1.SelectedIndex =
val1 and ddl2.SelectedIndex = 0
SelectDropDownValue(ddl2, val2); //after this, ddl1.SelectedIndex
= val2 and ddl2.SelectedIndex = val2
//after this, every change that i make to ddl1.SelectedIndex is also
affecting at the same time to ddl2.SelectedIndex and IDEM with
VICEVERSA.
Is it normal?
Thanks in advance