Dropdownlist, EditCommand in datagrid

J

jhcorey

I've been googling this and know it's been covered often, but I can't
get mine to work.

I'm using a dropdown list when editing the record in the datagrid.
I'm testing this using an arraylist to populate the dropdown.

The problem is in selecting the item in the dropdown that corresponds
to
the current record's value.

I have the function below wired to the EditCommand event. I'm looking
for the simplest way to select the correct value in the dropdownlist.
I notice in the OnItemDataBound I
have to cast the item cells to textboxes when the item is being edited,
but I'm not sure how to find the value I need.

private void dg_Columns_Edit(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dg_Columns.EditItemIndex = e.Item.ItemIndex;
rptDataTypes = new ArrayList();
rptDataTypes.Add("DESC");
rptDataTypes.Add("ASC");

FillColumnGrid();
DropDownList dl =

((DropDownList)dg_Columns.Items[e.Item.ItemIndex].Cells[5].FindControl("ddlSortDir"));
dl.DataSource = rptDataTypes;
dl.DataBind();

}
 

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,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top