hi. going through the white papers trying to figure out how to get my grid to load as edit mode, allow me update several rows, and then select one button to update them all. I went through a combination of Batch update, but that one is silly as it still wants you to select the rows you want to edit, (http://www.telerik.com/help/aspnet-ajax/grdperformingbatchupdates.html) and default edti mode on load (http://www.telerik.com/help/aspnet/grid/grddefaulteditmodeforgriditemsoninitialload.html) which is close but still wants you to click update on every row. I managed to get the grid to load into edit mode when paging but cannot get the itemcommand to recognize new data after the first page. The first page updates exactly as expected. My requirements are to stay load into and stay in edit mode, page through items and update on other pages all with the same single button.
Code and Souce
Source
Code and Souce
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) |
If (e.CommandName = "UpdateAll") Then |
For Each editedItem As GridEditableItem In RadGrid1.EditItems |
Dim newValues As Hashtable = New Hashtable |
'The GridTableView will fill the values from all editable columns in the hash |
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem) |
If newValues("Balance") IsNot Nothing Then 'WITHOUT THIS THE WHERE CLAUSE FAILS EACH TIME ON NEW PAGES. |
SqlDataSource1.UpdateCommand = String.Format("Update Account SET Balance= {0} WHERE ID= {1} ", newValues("Balance"), editedItem.GetDataKeyValue("ID").ToString()) |
SqlDataSource1.Update() |
End If |
editedItem.Edit = True |
Next |
End If |
multiEdit() |
RadGrid1.Rebind() |
End Sub |
Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.DataBound |
If IsPostBack Then |
multiEdit() |
End If |
End Sub |
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender |
If Not IsPostBack Then |
multiEdit() |
RadGrid1.Rebind() |
End If |
End Sub |
Sub multiEdit() |
For Each item As GridItem In RadGrid1.MasterTableView.Items |
If TypeOf item Is GridEditableItem Then |
Dim editableItem As GridEditableItem = CType(item, GridDataItem) |
editableItem.Edit = True |
End If |
Next |
End Sub |
Source
<asp:SqlDataSource ID="SqlDataSource1" runat="server" |
ConnectionString="<%$ ConnectionStrings:PHCJobPostsConn %>" |
SelectCommand="SELECT * FROM [Account]" |
</asp:SqlDataSource> |
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowEdit="True" DataSourceID="SqlDataSource1" |
OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound"> |
<MasterTableView DataKeyNames="ID" AutoGenerateColumns="false" EditMode="InPlace" |
CommandItemDisplay="TopAndBottom"> |
<Columns> |
<telerik:GridBoundColumn ReadOnly="true" DataField="ID" DataType="System.Int32" HeaderText="ID" SortExpression="ID" UniqueName="ID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn ReadOnly="true" DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn ReadOnly="true" DataField="AccountNo" HeaderText="AccountNo" SortExpression="AccountNo" UniqueName="AccountNo"> |
</telerik:GridBoundColumn> |
<telerik:GridTemplateColumn> |
<ItemTemplate> |
<%#Eval("Balance")%> |
</ItemTemplate> |
<EditItemTemplate> |
<asp:TextBox CssClass="none" ID="BalanceTB" Text='<%#Bind("Balance") %>' runat="server" /> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn ReadOnly="true" DataField="InsertDate" DataType="System.DateTime" HeaderText="InsertDate" SortExpression="InsertDate" UniqueName="InsertDate"> |
</telerik:GridBoundColumn> |
</Columns> |
<CommandItemTemplate> |
<asp:Button runat="server" ID="UpdateAll" Text="Update All" CommandName="UpdateAll" /> |
</CommandItemTemplate> |
</MasterTableView> |
</telerik:RadGrid> |