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

RadGrid Edit Template

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Varun
Top achievements
Rank 1
Varun asked on 20 Aug 2013, 09:34 PM
Hi,

We have a dropdown and add button inside edit template of radgrid column, We have a functionality wherein inside the edit mode of a row of radgrid we populate the dropdown and then on clicking the add button open a radwindow to add a new item to dropdown. When the radwindow is closed the dropdown inside the edit template should refresh and show this new item.

Can someone please guide me in achieving the above functionality.

Thanks 

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Aug 2013, 06:33 AM
Hello,

<form id="form1" runat="server">
   <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
   </telerik:RadScriptManager>
   <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
   </telerik:RadWindowManager>
   <telerik:RadWindow ID="RadWindow1" runat="server" Modal="true">
       <ContentTemplate>
           <asp:Label ID="Label1" runat="server"></asp:Label>
           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
           <asp:Button ID="Button2" runat="server" Text="Save" OnClick="Button2_Click" />
       </ContentTemplate>
   </telerik:RadWindow>
   <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="RadGrid1">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                   <telerik:AjaxUpdatedControl ControlID="RadWindow1" />
               </UpdatedControls>
           </telerik:AjaxSetting>
           <telerik:AjaxSetting AjaxControlID="Button2">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
   </telerik:RadAjaxManager>
   <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
   </telerik:RadAjaxLoadingPanel>
   <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
       <MasterTableView DataKeyNames="ID">
           <Columns>
               <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
               </telerik:GridBoundColumn>
               <telerik:GridTemplateColumn>
                   <ItemTemplate>
                       <%# Eval("Name") %>
                   </ItemTemplate>
                   <EditItemTemplate>
                       <telerik:RadComboBox ID="RadComboBox1" runat="server">
                       </telerik:RadComboBox>
                       <asp:Button ID="Button1" runat="server" Text="Add" OnClick="Button1_Click" />
                   </EditItemTemplate>
               </telerik:GridTemplateColumn>
               <telerik:GridEditCommandColumn>
               </telerik:GridEditCommandColumn>
           </Columns>
       </MasterTableView>
   </telerik:RadGrid>
   </form>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data1 = new[] {
             new { ID = 1, Name ="Name_1"},
             new { ID = 2, Name = "Name_2"},
             new { ID = 3, Name = "Name_1"},
             new { ID = 4, Name = "Name_4"},
             new { ID = 5, Name = "Name_1"}
         };
 
       RadGrid1.DataSource = data1;
   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       GridEditableItem item = (sender as Button).NamingContainer as GridEditableItem;
       Label1.Text = item.GetDataKeyValue("ID").ToString();
       TextBox1.Text = string.Empty;
       RadWindow1.VisibleOnPageLoad = true;
   }
   protected void Button2_Click(object sender, EventArgs e)
   {
       foreach (GridDataItem item in RadGrid1.EditItems)
       {
           if (item.GetDataKeyValue("ID").ToString() == Label1.Text)
           {
               RadComboBox RadComboBox1 = item.EditFormItem.FindControl("RadComboBox1") as RadComboBox;
               RadComboBox1.Items.Add(new RadComboBoxItem(TextBox1.Text, TextBox1.Text));
           }
       }
       RadWindow1.VisibleOnPageLoad = false;
   }


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