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

Template with user control

1 Answer 61 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, 10:11 AM
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, 12:32 PM
Hello Jerome,

Try out the following code to accomplish the required scenario.
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; 
            // remove the item from the bound list (5 - index of the item) 
            rdcbx.Items.Remove(5); 
            rdcbx.Items[0].Text = "134";      
        } 
    } 
Hope this helps..

Thanks
Princy



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