setting the default item on a dropdownlist inside a datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a DropDownList that is bind to my DataGrid's EditItemTemplate
The datasource of my DDL is different from my datagrid's datasource

Everytime the 'Edit' link is clicked, the default item of the DDL is set to the first item in it
How can I select the 'actual' default item when the 'Edit' link is being clicked

Please Help..Thanks in advanc

Regards,
Audrey
 
On itemdatabound event of datagrid you can do the following


Get the actualItem by
if(e.item.ItemType==ListItemType.EditItem)
{
DataRowview drv=(DataRowView)e.item.DataItem;
string actual=drv["ColumnName"].toString();
DropDownList ddl=(DropDownList)e.item.FindControl("yourDropDownListName");
ddl.SelectedIndex=ddl.Items.IndexOf(ddl.Items.FindByValue(actual));

}


or you can also fo FineByText depending upon the situation.

-Ajay
 
----- Ajay wrote: -----

On itemdatabound event of datagrid you can do the following


Get the actualItem by
if(e.item.ItemType==ListItemType.EditItem)
{
DataRowview drv=(DataRowView)e.item.DataItem;
string actual=drv["ColumnName"].toString();
DropDownList ddl=(DropDownList)e.item.FindControl("yourDropDownListName");
ddl.SelectedIndex=ddl.Items.IndexOf(ddl.Items.FindByValue(actual));

}


or you can also fo FineByText depending upon the situation.

-Ajay
-----------------------------------------------------------------------------------
Hi Ajay,

I've tried it using ur way..
It doesn't work..
i've tried to debug it and the If'Else statement is false..
the value of 'e.item.ItemType' is 'header'

Please Advice
Audrey
 
Back
Top