ComboBox inside UseControl for RadGrid Edit Form

4 posts, 1 answers
  1. Karen
    Karen avatar
    27 posts
    Member since:
    Jul 2008

    Posted 01 Jul 2009 Link to this post

    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?
  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 01 Jul 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Karen
    Karen avatar
    27 posts
    Member since:
    Jul 2008

    Posted 02 Jul 2009 Link to this post

    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.
  5. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 02 Jul 2009 Link to this post

    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.
Back to Top