Setting SelectedValue in DataGrid's DropDownLists


A

AlBruAn

I have an application I'm working on in which I'm wanting to default to
displaying the previously selected value from a dropdownlist whenever the
user opts to edit a record in the datagrid control. I'm able to grab the
previously selected value from the text box, but I can't set the
SelectedValue in the corresponding dropdownlist equal to it. Code is as
follows:

458 Control ctl;
459 DataGridItem dgRow = e.Item;
460
461 ctl = e.Item.FindControl("lblFlooring");
462 currFlooring = ((Label)ctl).Text;
463
464 DataGrid1.EditItemIndex = e.Item.ItemIndex;
465 BindGrid();
466
467 ((DropDownList)dgRow.FindControl("ddlFlooring")).SelectedValue =
currFlooring;

When I attempt to execute line 467 in this code, I get the standard ""Object
reference not set to an instance of an object." message. BTW, lblFlooring is
the label containing the flooring material prior to entering the Edit mode
and ddlFlooring is the dropdownlist containing flooring materials once a row
has been placed in Edit mode. Anyway, is there another way of setting the
SelectedValue as part of the datagrid's EditCommand function? Any help would
be greatly appreciated.
 
Ad

Advertisements

A

AlBruAn

Never mind. I needed to add an OnPreRender reference to a function in the
HTML defining the dropdownlist In said function, I grab the ListControl for
the DropDownList and set its SelectedValue equal to what'd previously been
displayed in that cell.
 

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

Top