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

Find the controls inside the Form Template in the page load event

1 Answer 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
parmesh
Top achievements
Rank 1
parmesh asked on 17 Jan 2012, 04:57 PM
Hi,

Can anyone let me know how to bind the check box list inside the form template of radgrid in the pageload event
or
any alternative solution for the above requirement 
or
Find the controls inside the Form Template in the page load event 

I have checked this link.
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx
but they are binding the dropdown with static values.  I want to bind the dropdown on the fly in page load

Thanks in advance
Parmesh

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Jan 2012, 06:56 PM
Hello parmesh,

please check itemdatabound event in below code.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
           onitemdatabound="RadGrid1_ItemDataBound"
           onneeddatasource="RadGrid1_NeedDataSource"
           onprerender="RadGrid1_PreRender">
           <MasterTableView DataKeyNames="ID" EditMode="EditForms">
           <Columns>
               <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID"></telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"></telerik:GridBoundColumn>
               <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
           </Columns>
           <EditFormSettings EditFormType="Template">
               <FormTemplate>
               <div>
               <telerik:RadComboBox ID="RadComboBox1" runat="server"></telerik:RadComboBox>
               </div>
               </FormTemplate>
               </EditFormSettings>
           </MasterTableView>
            
   </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
                new { ID = 1, Name ="name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "name3"},
                new { ID = 4, Name = "Name4"},
                new { ID = 5, Name = "name5"}
            };
            RadGrid1.DataSource = data;
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode && e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                RadComboBox RadComboBox1 = item.FindControl("RadComboBox1") as RadComboBox;
 
                dynamic data = new[] {
                new { ID = 1, Name ="name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 5, Name = "name5"}
            };
 
                RadComboBox1.DataSource = data;
                RadComboBox1.DataTextField = "ID";
                RadComboBox1.DataValueField = "ID";
                RadComboBox1.DataBind();
            }
        }
 
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RadGrid1.EditIndexes.Add(0);
                RadGrid1.Rebind();
            }
        }

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
parmesh
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or