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

Can;t extract values from GridDropDown

2 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hk
Top achievements
Rank 2
Hk asked on 15 Mar 2009, 03:11 PM
Hi Telerik,
I have a grid with a dropDownColumn:
<telerik:GridDropDownColumn DataField="bitPRI" HeaderText="bitPRI" SortExpression="bitPRI" 
                            UniqueName="bitPRI" DropDownControlType="DropDownList" ForceExtractValue="Always"
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
                        </telerik:GridDropDownColumn>

I must populate manually the dropdown every time I enter to edit mode. So I populate it manually, but before that I want to save the selected value so I can focus on the selection in the drop down again.
This is two methods I tried BEFORE I re-populate the dropdown:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
 
 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem eeditedItem = e.Item as GridEditableItem; 
                GridEditManager editMan = editedItem.EditManager; 
 
GridDropDownListColumnEditor editor_bitPRI = (GridDropDownListColumnEditor)(editMan.GetColumnEditor("bitPRI")); 
                GridDropDownColumnEditor editor_bitPRI_TEST = (GridDropDownColumnEditor)(editMan.GetColumnEditor("bitPRI")); 
System.Diagnostics.Debug.WriteLine(editor_bitPRI_TEST.SelectedValue); 
System.Diagnostics.Debug.WriteLine(editedItem["bitPRI"].Text); 
DropDownList editor_bitPRIeditor_bitPRIComboBoxControl = editor_bitPRI.DropDownListControl; 
System.Diagnostics.Debug.WriteLine(editor_bitPRI.DropDownListControl.SelectedValue); 
 
 
 
none is showing the correct selected value. Keep in mind that before I re-populate the combo, the items count is 0. But I still want to retain the last saved value!

2 Answers, 1 is accepted

Sort by
0
Reid
Top achievements
Rank 2
answered on 15 Mar 2009, 11:43 PM
Hello Hk,

I am relatively new to Telerik but I can say I have ran into this many times as well.  In fact on a side note I would not recommend using a user control in a FormTemplate (I know you are not in this case, just a warning) because I have not had luck setting or getting the values from any of the user control's embedded controls with any strategy.  Sometimes it would find the embedded control, I would fill the values and yet when the page loaded the values would be empty.

What I have done that works is to

  1. Save the value or object into the session inside the ItemCommand event handler
  2. Add a custom method that fills and sets the selected item in the DropDownList
  3. Call that custom method in the Page's PreRender() event
If I just call the custom method (i.e. SetupCustomerFormTemplate() ) from inside the ItemCommandHandler, the DropDownList is never found using a typical FindControl() call, only after the PreRender Page event fires and the custom method is called again does it find it, fill it, and set the selected index. 

I suspect our Telerik friends will show us how to extract it in a "Telerik" way, and I am interested in finding out the details of that.

Reid
0
Hk
Top achievements
Rank 2
answered on 16 Mar 2009, 09:10 AM
Hi Reid,
Thanks for your answer. The problem is I have several columns with combo, and also I want to save these values when the user returns to the app after he shuts down the browser - so session variables will not work here. I would like to see if there is a Telerik right way to do it... currently I can't find any.
Tags
Grid
Asked by
Hk
Top achievements
Rank 2
Answers by
Reid
Top achievements
Rank 2
Hk
Top achievements
Rank 2
Share this question
or