DataGrid with Dropdown list

V

vijay_kerji

Any Help is appreciated!
I have a datagrid with Drop down list and a remove hyperlink as two
columns.
When I remove the row of the datagrid by clicking on the remove
column,Dropdown list is mentaining its previous state.
i.e Removed dropdownlist's selected value is applied to the next
datagrid item's dropdown list.

DATAGRID
---------------------------------------------------------
"Remove" | "<DropDownList1>"
---------------------------------------------------------
"Remove" | "<DropDownList2>""


When the first row is removed, "DropDownList2" becomes
"DropDownList1"!!!

How to solve this problem?

Thanks
Vijay
 
V

Vijay Kerji

Samuel Kim said:
Can you pls post some of the code you are using?

Hi,
The following code is used in the 'remove' hyperlink click handler.

foreach(DataGridItem DemoGridItem in dataGrid_AddUsers.Items)
{
DropDownList myDDList =
(DropDownList)DemoGridItem.Cells[3].Controls[1];
string selectedValue =
((DataGridUser)this.userList[index]).userRole;
//Check if the program is in edit or create
//If it is in edit, disable the datagrid item row and do not add
PM as dropdownlist item.
if ("ProgramEdit" == programModeValue)
{
if(selectedValue == "PM")
{
myDDList.Items.Add("PM");
DemoGridItem.Enabled = myDDList.Enabled = false;
myDDList.Items.FindByText(((DataGridUser)this.userList[index]).userRole).Selected
= true;
//myDDList.SelectedValue
=((DataGridUser)this.userList[index]).userRole;
} //if the role is null which is a bug in DB
else if (selectedValue == "")
{
myDDList.Items.Add("Sub PM");
myDDList.Items.Add("CBA");
myDDList.Items.Add("Stake Holder");
}
else //since we are in edit mode, add all except PM
{
myDDList.Items.Add("Sub PM");
myDDList.Items.Add("CBA");
myDDList.Items.Add("Stake Holder");
myDDList.Items.FindByText(((DataGridUser)this.userList[index]).userRole).Selected
= true;
//myDDList.SelectedValue
=((DataGridUser)userList[index]).userRole;
}
}
else //we are in create mode, add all the values to the list.
{
myDDList.Items.Add("PM");
myDDList.Items.Add("Sub PM");
myDDList.Items.Add("CBA");
myDDList.Items.Add("Stake Holder");
//set the selected value
myDDList.Items.FindByText(((DataGridUser)this.userList[index]).userRole).Selected
= true;
//myDDList.SelectedValue
=((DataGridUser)userList[index]).userRole;
}
index++;
}

Hope it is readable.

Thanks

Vijay
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top