How to display selectedvalue of a dorpdownlist into a grid in Edit mode

May 23 2008 6:12 AM

Hi,

I have a dropdownlist into a datagrid as a template field, which is not connected to the database. I'm using it only for display.

For the dropdownlist I have the following procedure:

protected ArrayList GetGroup()

{

ArrayList groups = new ArrayList();

groups.Add("");

groups.Add("Adult");

groups.Add("3rd Adult");

groups.Add("1st Child");

groups.Add("2nd Child");

...

return groups;

}

I need to display the selected values from this dropdownlist in EditMode of the datagrid.

for this I have the following function:

public void grdEdit_Click(object sender, DataGridCommandEventArgs e)

{

grdPersonGroups.EditItemIndex = e.Item.ItemIndex;

grdPersonGroups.DataSource = GetContractPersonGroup();

grdPersonGroups.DataBind();

foreach (DataGridItem item in grdPersonGroups.Items)

{

DetermineGroupSelection(item);

}

}

DetermineGroupSelection(item) is a function that contains a Switch Case in wich I take the selectedvalue of the dorpdownlist.

My problem is when I  click on Edit link in DataGrid, in edit mode the selected value of dropdownlist is null. I can see only the other values from datagrid.

Can someone help me?

Thank you