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

User control and template in RadGrid

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jerome
Top achievements
Rank 1
Jerome asked on 12 Aug 2008, 12:23 PM
Hello.

I have a RadGrid with an edit item template. In this template, I put a user control. In this user control i have a RadComboBox.
When i click on edit in my RadGrid, the selected value of the RadComboBox is always the first.

Here, the page_load of the user control :
protected void Page_Load(object sender, EventArgs e)  
        {  
            if (RCBFrequencesUserControl.Items.Count == 0)  
            {  
                RCBFrequencesUserControl.DataSource = Params.GetFrequence(webUtility.getConnectedUser());  
  
                RCBFrequencesUserControl.DataTextField = "libelle";  
                RCBFrequencesUserControl.DataValueField = "idfrequence";  
                RCBFrequencesUserControl.DataBind();  
                RCBFrequences.SelectedValue = "134";  
                  
            }  
        }  

The selected value is 134, but on the radgrid edit item template, the selected value is always the first.

I have try  it on a simple page, it works.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Aug 2008, 01:26 PM
Hello Jerome,

You can set the selected value, as the topmost item of the RadComboBox as shown below in the code snippet.
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn">         
        <EditItemTemplate>  
            <uc:UserControl runat="server" ID="UserControl1" />  
        </EditItemTemplate>  
</telerik:GridTemplateColumn>  

cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem item = e.Item as GridEditFormItem;  
            RadComboBox rdcbx = item.FindControl("UserControl1").FindControl("RadComboBox1") as RadComboBox;  
            rdcbx.Items.Remove(3);  
            rdcbx.Items[0].Text = "134";       
        }  
    }  

Thanks
Princy.
Tags
Grid
Asked by
Jerome
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or