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

Batch Update Radgrid

1 Answer 78 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Chad asked on 03 Jan 2014, 06:07 PM
I have a radgrid with various ddl and radcalendars in the cells within the rows that are all editible.  What I would like to do is be able to loop through and update all editable cells within the rows of myradgrid at the same time.  I have found numerous articles on batch editing when in edit view but I would like to upadate in user view.

Below is my code.





<asp:Panel ID="pnlGrid" runat="server" CssClass="panelGrid">




<telerik:RadGrid ID="myRadGrid" runat="server" Width="90%" Skin="Web20" CssClass="dvGridWrapper" AllowSorting="true">




<PagerStyle AlwaysVisible="true" />




<MasterTableView AutoGenerateColumns="false" Font-Size="10" DataKeyNames="intRecruitId" CommandItemDisplay="Bottom">




<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />




<HeaderStyle ForeColor="White" Font-Bold="true" HorizontalAlign="Center" />




<AlternatingItemStyle BackColor="#B0C4DE" HorizontalAlign="Center" />








<asp:LinkButton ID="lnkUpdateAll" runat="server" CommandName="UpdateAll" CommandArgument='<%#Bind("intRecruitId")%>'>Update All</asp:LinkButton>












<telerik:GridBoundColumn DataField="dtRSPStatusChanged" HeaderText="Last Changed" />




<telerik:GridTemplateColumn HeaderText="NAME">








<asp:LinkButton ID="lnkName" runat="server" Text='<%#Bind("Name")%>' CommandArgument='<%#Bind("intRecruitId")%>' CommandName="pnlOpen" ToolTip="Click to See Data"></asp:LinkButton>












<telerik:GridTemplateColumn HeaderText="PHASE" UniqueName="Phase">








<asp:DropDownList ID="ddlPhase3" runat="server" SelectedValue='<%#Bind("intPhaseId")%>'>




<asp:ListItem Value="1" Text="Red" />




<asp:ListItem Value="2" Text="White1" />




<asp:ListItem Value="3" Text="White2" />




<asp:ListItem Value="4" Text="White3" />




<asp:ListItem Value="5" Text="Blue" />




<asp:ListItem Value="6" Text="Green" />




<asp:ListItem Value="7" Text="Gold" />
















<telerik:GridTemplateColumn DataField="dtShip" HeaderText="SHIP DATE">








<telerik:RadDatePicker ID="rdp_dtShip" runat="server" DbSelectedDate='<%#Bind("dtShip")%>' Width="100px"></telerik:RadDatePicker>












<telerik:GridBoundColumn DataField="ddDate" HeaderText="DROP DEAD DATE" />




<telerik:GridTemplateColumn DataField="dtProjReturn" HeaderText="EST RETURN DATE">








<telerik:RadDatePicker ID="rdp_Return" runat="server" DbSelectedDate='<%#Bind("dtProjReturn")%>' Width="100px"></telerik:RadDatePicker>












<telerik:GridTemplateColumn HeaderText="STATUS" UniqueName="Status">








<asp:DropDownList ID="ddlStatus3" runat="server" SelectedValue='<%#Bind("intRSPStatusID")%>'>




<asp:ListItem Value="1" Text="Amber" />




<asp:ListItem Value="3" Text="DAT" />




<asp:ListItem Value="4" Text="Discharged" />




<asp:ListItem Value="5" Text="Green" />




<asp:ListItem Value="6" Text="Hardship" />




<asp:ListItem Value="7" Text="Test" />




<asp:ListItem Value="8" Text="OCS" />




<asp:ListItem Value="9" Text="Pend Dis" />




<asp:ListItem Value="10" Text="Prior SVC" />




<asp:ListItem Value="11" Text="Qualified" />




<asp:ListItem Value="12" Text="Red" />




<asp:ListItem Value="13" Text="Shipped" />




<asp:ListItem Value="18" Text="None" />




<asp:ListItem Value="19" Text="NAC" />




<asp:ListItem Value="20" Text="IST" />




<asp:ListItem Value="21" Text="Gold" />




<asp:ListItem Value="22" Text="Not Entered" />




<asp:ListItem Value="23" Text="Recruit Force Pool" />
















<telerik:GridTemplateColumn HeaderText="ISSUE" UniqueName="Issue">








<asp:DropDownList ID="ddlIssue3" runat="server" SelectedValue='<%#Bind("intRSPIssueID")%>' >




<asp:ListItem Value="1" Text="Admin" />




<asp:ListItem Value="2" Text="APFT" />




<asp:ListItem Value="3" Text="Attendance" />




<asp:ListItem Value="5" Text="BCT" />




<asp:ListItem Value="6" Text="Testing" />




<asp:ListItem Value="7" Text="Test2" />




<asp:ListItem Value="8" Text="Education Fail" />




<asp:ListItem Value="9" Text="Family hardship" />




<asp:ListItem Value="10" Text="Legal" />




<asp:ListItem Value="11" Text="Medical" />




<asp:ListItem Value="12" Text="New Trainee" />




<asp:ListItem Value="13" Text="Packet failure" />




<asp:ListItem Value="14" Text="None" />




<asp:ListItem Value="15" Text="Not Entered" />




<asp:ListItem Value="16" Text="Education HSJR" />




<asp:ListItem Value="17" Text="Education HSSR" />




<asp:ListItem Value="18" Text="Education GED" />




<asp:ListItem Value="19" Text="Pend PH2 Date" />




<asp:ListItem Value="20" Text="Pend IST" />




<asp:ListItem Value="21" Text="College" />




<asp:ListItem Value="22" Text="OCS" />




<asp:ListItem Value="23" Text="ROTC" />




<asp:ListItem Value="24" Text="ROTC SMP" />




<asp:ListItem Value="25" Text="Pend OCS Date" />




<asp:ListItem Value="26" Text="Pend RENO Out" />




<asp:ListItem Value="27" Text="Pending Commission" />
















<telerik:GridTemplateColumn HeaderText="EDUCATION" UniqueName="Ed">








<asp:DropDownList ID="ddlEd3" runat="server" SelectedValue='<%#Bind("intRSPEdID")%>' >




<asp:ListItem Value="1" Text="N/A" />




<asp:ListItem Value="2" Text="HSSR" />




<asp:ListItem Value="3" Text="HSJR" />




<asp:ListItem Value="4" Text="GED +" />




<asp:ListItem Value="5" Text="GED" />




<asp:ListItem Value="6" Text="GRAD" />




<asp:ListItem Value="7" Text="COLLEGE" />
















<telerik:GridTemplateColumn HeaderText="NOTES">









<asp:Image ID="imgLooker" runat="server" ImageUrl="~/Images/ViewResources.gif" ImageAlign="Middle" BorderStyle="None" />




<asp:PopupControlExtender ID="popInfo" runat="server" PopupControlID="pnlPop" TargetControlID="imgLooker" DynamicContextKey='<% #Eval("intRSPNotesID")%>'




DynamicControlID="pnlpop" DynamicServiceMethod="GetNotes" Position="bottom"></asp:PopupControlExtender>












<telerik:GridBoundColumn DataField="strRSPSiteLocation" HeaderText="RSP SITE" />




<telerik:GridBoundColumn DataField="strUIC" HeaderText="UIC" />




<telerik:GridTemplateColumn HeaderText="UPDATE">








<asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" ToolTip="Click to Save Data" CommandArgument='<%#Bind("intRecruitId")%>' CommandName="Update"></asp:LinkButton>
















<BatchEditingSettings EditType="Cell" />










Code Behind



If (e.CommandName = "UpdateAll") Then




Dim recruitid As Integer = Convert.ToInt32(e.CommandArgument = "intRecruitId")




'Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)




Dim Phase As DropDownList = DirectCast(e.Item.FindControl("ddlPhase3"), DropDownList)




Dim Status As DropDownList = DirectCast(e.Item.FindControl("ddlStatus3"), DropDownList)




Dim Issue As DropDownList = DirectCast(e.Item.FindControl("ddlIssue3"), DropDownList)




Dim Ed As DropDownList = DirectCast(e.Item.FindControl("ddlEd3"), DropDownList)




Dim dtShip As TextBox = DirectCast(e.Item.FindControl("txtdtShip"), TextBox)




Dim dtReturn As TextBox = DirectCast(e.Item.FindControl("txtProjRtn"), TextBox)




Dim myDataGridItem As DataGridItem




For Each DataGridItem In myRadGrid.Items



sql =


"Update tblRSP SET dtProjReturn = '" & sanitizeString(dtReturn.Text) & "', intRSPStatusID = " & Status.SelectedValue & ", intRSPIssueID = " & Issue.SelectedValue & ", INTRSPEdID = " & Ed.SelectedValue & ", intPhaseID = " & Phase.SelectedValue & "" _




" Where intRecruitId =" & recruitid & " Update Recruit SET dtShip = '" & sanitizeString(dtShip.Text) & "' Where intRecruitId =" & recruitid












End If


1 Answer, 1 is accepted

Sort by
Angel Petrov
Telerik team
answered on 08 Jan 2014, 11:56 AM
Hi Chad,

The main-points in creating such a solution would be:
  1. Obtaining a reference to the controls in the ItemTemplate of the different GridTemplateColumns
  2. Extracting their value and updating the relevant database record
  3. Rebinding the grid thus effectively applying the changes(the .Rebind() call should be executed once all the items are updated)

If we refer to the provided code you can do something like this:


If (e.CommandName = "UpdateAll") Then
           For Each DataGridItem In myRadGrid.Items
               Dim Phase As DropDownList = DirectCast(DataGridItem.FindControl("ddlPhase3"), DropDownList)
               Dim Status As DropDownList = DirectCast(DataGridItem.FindControl("ddlStatus3"), DropDownList)
               Dim Issue As DropDownList = DirectCast(DataGridItem.FindControl("ddlIssue3"), DropDownList)
               Dim Ed As DropDownList = DirectCast(DataGridItem.FindControl("ddlEd3"), DropDownList)
               Dim dtShip As TextBox = DirectCast(DataGridItem.FindControl("txtdtShip"), TextBox)
               Dim dtReturn As TextBox = DirectCast(DataGridItem.FindControl("txtProjRtn"), TextBox)
               'Update the record in the database using the controls values
       End If

Additionally I would like to ask you to use the code formatting tool when submitting code samples. This makes them easier to read as additional formatting is not required.
Angel Petrov
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 the blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question