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

How do I set the initial value for a dropdown?

1 Answer 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 16 Aug 2011, 10:48 PM
I have a dropdownlist editor as a column. I have loaded it with the values "", "s", "m"

I have an object that has an "s" stored in it...when I initialize the editor I would like to load the initial value that the object has in it....but I can't get it to work. The value of the cell is always null even after I set it.

Thoughts?

private void rgcSoil_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            if (e.Column.Name != "colSorM")
                return;
 
            RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
            if (editor != null)
            {
                var ee = (RadDropDownListEditorElement)((RadDropDownListEditor)this.rgcSoil.ActiveEditor).EditorElement;
                ee.BeginEdit();
                ee.DataSource = new String[] {"", "S", "M" };
                SoilType st = (SoilType)e.Row.Tag;
 
                ee.Value = st.StandardOrModified;
                ee.EndEdit();
            }
        }

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 Aug 2011, 09:19 AM
Hello David,

Thank you for writing.

I am not sure I fully understand your scenario. If you want to have different data sources for each row of GridViewComboBoxColumn, please refer to the following KB article. Otherwise, if the binding is OK and you just want to set the value of the active editor, you can do that with the following code in the CellEditorInitialized event handler:
e.ActiveEditor.Value= st.StandardOrModified;

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
 
Kind regards,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or