setting the default item on a dropdownlist inside a datagrid

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
 
G

Guest

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
 
G

Guest

----- 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
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top