This is a migrated thread and some comments may be shown as answers.

Drop Down Value Retrieval Error

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Susan
Top achievements
Rank 1
Susan asked on 19 Aug 2011, 08:28 PM
I've got another RadGrid problem. One column in my grid is a DropDown that is getting its values from a SqlDataSource. The cell is defined as:
<telerik:GridDropDownColumn DataField="store" HeaderText="Store" UniqueName="store" DataSourceID="SqlDataSource2"
       ListTextField="store" ListValueField="store">
</telerik:GridDropDownColumn>

The drop down list is getting populated fine. I am using edit in place for the editing and can select a value from the list okay. On the back end for the update, I've got (in part):
protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {           
        string store = (editedItem["store"].Controls[0] as DropDownList).SelectedValue.ToString();
    }

I'm getting an error at run time after editing a row when I include that code. If I remove the code that adds the store drop down from the update, it works fine (but of course doesn't update that field.) I've tried other variations such as "string store = (editedItem["store"].Controls[0] as DropDownList).SelectedItem.Value" with no luck.

The error is "Message: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
Line: 6
Char: 62099
Code: 0"

Any ideas? Thanks!

1 Answer, 1 is accepted

Sort by
0
Susan
Top achievements
Rank 1
answered on 20 Aug 2011, 08:32 PM
Never mind... looks like I found the answer in an old forum post from 2008. Don't know why, but I needed to reference the dropdown box as a combobox! Here's the code that got the value:

string store = (editedItem["store"].Controls[0] as RadComboBox).SelectedValue;

store is setup as a GridDropDownColumn in the form, but the page only worked when I referred to it as a RadComboBox in the code-behind.
Tags
Grid
Asked by
Susan
Top achievements
Rank 1
Answers by
Susan
Top achievements
Rank 1
Share this question
or