How can I get a label's value in a datagrid for a dropdownlist?

N

needin4mation

I have a dropdownlist that I want to default to the proper value in the
list. It should be what the current value of the label is before I
press edit.

Any ideas?
 
N

needin4mation

if(e.Item.ItemType == ListItemType.EditItem)
{
//how to find the current value that is in the database and use that
//as the way to preselect the appropriate item from the dropdownlist
//http://msdn.microsoft.com/library/d...QuestionsAboutASPNETDataGridServerControl.asp

DataRowView drvCity = (DataRowView) e.Item.DataItem;
String CurrentCity = drvCity["city_code"].ToString(); //city_code is
the database column
DropDownList ddlCity = (DropDownList)
e.Item.FindControl("ddl_edit_cities");
ddlCity.SelectedIndex =
ddlCity.Items.IndexOf(ddlCity.Items.FindByText(CurrentCity));

DataRowView drvEdit = (DataRowView) e.Item.DataItem;
String CurrentIndicator = drvEdit["indicator"].ToString();
DropDownList ddlEdit = (DropDownList)
e.Item.FindControl("ddl_edit_indicator");
ddlEdit.SelectedIndex =
ddlEdit.Items.IndexOf(ddlEdit.Items.FindByValue(CurrentIndicator));
//notice this last one is FindByValue because the values in the
listitems
//are different than than the text displayed to the user
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top