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

[Solved] RadGrid Batch Updating

3 Answers 327 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 15 Jun 2009, 09:44 PM
So I've created a grid that has a number of template columns that should remain entirely in "edit mode" (I set this in my C# code) so that I can edit my grid "live" (Excel like). Below is just a portion of my grid. When I'm trying to do the update, however, I don't know how to read the values from each cell in the grid. I've tried to do loops  such as Radgrid1.Items[i].Cells[j], and Radgrid1.Items[i].ExtractValues. I've also followed the batch update on this site but this doesn't work either. The question comes down to: How can I get data from each cell of the RadGrid. The cells can be anything from drop down menus to text boxes. Any help would be greatly appreciated

-Matt
    
        <telerik:RadGrid ID="RadGrid1" runat="server" Width="70%" AllowPaging="True"  
            Height="400px" AllowMultiRowEdit="True"   
             BorderColor="Black" BorderWidth="1px"  
            onselectedindexchanged="RadGrid1_SelIndexChange"  
            onprerender="RadGrid1_PreRender"  
            OnItemCommand="RadGrid1_ItemCommand" 
            onNeedDataSource="RadGrid1_NeedDataSource1" onitemdatabound="RadGrid1_ItemDataBound"  
             AllowAutomaticUpdates="True" 
            > 
            <AlternatingItemStyle BackColor="#E8E8E8" Font-Bold="False" Font-Italic="False"  
                Font-Overline="False" Font-Strikeout="False" Font-Underline="False"  
                Wrap="True" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> 
            <MasterTableView AutoGenerateColumns="False"  
                Width="100%" BorderColor="Black" BorderWidth="0px" GridLines="None"  
                EditMode="InPlace"  
                CommandItemDisplay="TopAndBottom" > 
                <Columns>  
                 
           <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" /> 
                          
                    <telerik:GridTemplateColumn UniqueName="DeleteColumn" HeaderStyle-Width="70px"
                        <EditItemTemplate> 
                            <asp:Button ID="DeleteButton" runat="server" Text="Delete" /> 
                        </EditItemTemplate> 
 
<HeaderStyle Width="70px"></HeaderStyle> 
                    </telerik:GridTemplateColumn> 
 
                    <telerik:GridTemplateColumn DataField="role" HeaderText="Role"  
                        SortExpression="role" UniqueName="role" HeaderStyle-Width="150px"
                        <EditItemTemplate> 
                            <asp:Label ID="roleLabel" runat="server" Text='<%# Eval("role") %>' Width="150px"></asp:Label> 
                        </EditItemTemplate> 
                        <HeaderTemplate> 
                            <asp:Label ID="rol_label" runat="server" Text="Role"></asp:Label> 
                        </HeaderTemplate>                 
 
</Columns> 
                  <CommandItemTemplate> 
                       <asp:Button runat="server" ID="UpdateAll" Text="Update All" CommandName="UpdateAll" /></CommandItemTemplate
                 
                 
            </MasterTableView> 
             
            <ClientSettings> 
                <Selecting AllowRowSelect="True" /> 
                <Scrolling ScrollHeight="100%" AllowScroll="True"  /> 
                <resizing allowcolumnresize="True"  /> 
            </ClientSettings> 
        </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Jun 2009, 10:28 AM
Hello Mathew,

The ExtractValues method will work when you only have bound columns in your grid. When using Template columns, you can loop through the rows, find the controls placed in the EditItemTemplates using their Ids' and then  access values. Check out the code below which implements the same:
aspx:
 <telerik:GridBoundColumn DataField="ContactTitle" UniqueName="ContactTitle">  
 </telerik:GridBoundColumn> 
 <telerik:GridTemplateColumn> 
      <EditItemTemplate> 
           <asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource1" DataTextField="ContactName" runat="server"
           </asp:DropDownList> 
      </EditItemTemplate> 
 </telerik:GridTemplateColumn> 

c#:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "UpdateAll")  
        {  
            foreach (GridEditableItem editedItem in RadGrid1.EditItems)  
            {  
                DropDownList ddl = (DropDownList)editedItem.FindControl("DropDownList1");// for TemplateColumns 
                string name = ddl.SelectedItem.Text;  
                TextBox txtbx = (TextBox)editItem["ContactTitle"].Controls[0];// for BoundColumns 
                string title = txtbx.Text;  
                // update query  
            }  
        }  
 

Thanks
Princy.
0
Naresh
Top achievements
Rank 1
answered on 03 Apr 2013, 08:16 PM
I was looking for this finally i found it.. i have one more requirement on top it i.e. i have to update only rows that have been updated not to loop through all the rows in grid, (can we implement this?) .. Few posts talked about dirty row (http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-multi-row-questions.aspx)
 concept which would not work as extractvalues method will not work.
0
Eyup
Telerik team
answered on 02 May 2013, 12:00 PM
Hello Naresh,

In case you want to implement Batch updating, you can check out this example:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/clienteditbatchupdates/defaultcs.aspx

Hope this helps.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Naresh
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or