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

ComboBox inside UseControl for RadGrid Edit Form

3 Answers 143 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Karen
Top achievements
Rank 1
Karen asked on 01 Jul 2009, 11:04 AM
Hello

I am using User Control as Edit Form for RadGrid , there is a combo box inside that user control, how can I set the default value for that combo, in this example  there are only text boxes there and it is easy to set defaule values for them, but how about combo box?

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 01 Jul 2009, 11:44 AM
Hello Karen,

You could handle the DataBound event of that ComboBox and set its value there.

Sincerely yours,
Simon
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
0
Karen
Top achievements
Rank 1
answered on 02 Jul 2009, 10:04 AM
But how to get the value of the selected item from code behind?
I see in your example everything is bound in aspx page using <%# DataBinder.Eval(....) %> nothing is bound from code behind there.
0
Accepted
Simon
Telerik team
answered on 02 Jul 2009, 12:10 PM
Hello Karen,

In case you handle the ComboBox's DataBound event you could obtain the Grid Row's DataItem in this way:

protected void RadComboBox1_DataBound(object sender, EventArgs e) 
    RadComboBox comboBox = (RadComboBox)sender; 
    GridEditFormItem gridEditFormItem = (GridEditFormItem)comboBox.Parent.NamingContainer; 
    DataRowView dataItem = (DataRowView)gridEditFormItem.DataItem; 
    comboBox.SelectedValue = dataItem["ColumnName"].ToString(); 

Alternatively, you could handle the Grid's ItemDataBound event and achieve the same result as shown below:

private void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if(e.Item is GridEditFormItem && e.Item.IsInEditMode) 
    { 
        UserControl MyUserControl = e.Item.FindControl (GridEditFormItem.EditFormUserControlID) as UserControl; 
        GridDataItem parentItem = (e.Item as GridEditFormItem).ParentItem; 
        RadComboBox comboBox = (RadComboBox)MyUserControl.FindControl("RadComboBox1"); 
        comboBox.SelectedValue = parentItem["ColumnName"].Text; 
    } 


Regards,
Simon
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
Tags
ComboBox
Asked by
Karen
Top achievements
Rank 1
Answers by
Simon
Telerik team
Karen
Top achievements
Rank 1
Share this question
or