How to reference label in datagrid when pressing Edit?

N

needin4mation

Hi, consider this snippet, please:

private void dgdHistory_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string city=null;
if (e.Item.ItemType==ListItemType.Item)
{
Label city_data = ((Label)e.Item.FindControl("lbl_city"));
Response.Write("city: " + city_data.Text);
city = city_data.Text;
}

if (e.Item.ItemType==ListItemType.EditItem)
{
DropDownList ddl_city =
((DropDownList)e.Item.FindControl("ddl_edit_cities"));
ddl_city.SelectedValue = city;
Response.Write("CITY EDITITEM: " + city);
}
}

All I am trying to do is capture the value of my label's text and then
have my dropdownlist in my edititemtemplate default to that value.

So, if the current value of the city is Chicago, then when I press
Edit, the DropDownList should start at Chicago, not the first of the
list. However, I cannot figure out how to capture the current value of
the label to set the SelectedValue or SelectedIndex of the DropDownList
that appears when I press Edit.

Thank you for any help.
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top