我想批量编辑动态RadGridView。
动态RadGridView:与在标记中定义相反,我已经在PageInit中创建了gridview。这样做的缺点是,它会在每个回发页面上创建gridview。
问题是当我编辑第二行时,它回发并在PageInit中创建整个网格,结果第一行的值丢失了。单击下一行的编辑按钮时,如何存储前面所有行的值?
grdControl = New RadGrid()
grdControl.ID = "grid"
grdControl.Width = Unit.Pixel(1000)
grdControl.AllowSorting = True
grdControl.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
grdControl.AllowPaging = True
grdControl.AllowAutomaticUpdates = False
grdControl.EnableEmbeddedScripts = False
grdControl.AllowMultiRowEdit = True
grdControl.MasterTableView.AutoGenerateColumns = False
grdControl.MasterTableView.EnableColumnsViewState = False
grdControl.MasterTableView.EditMode = GridEditMode.InPlace
grdControl.MasterTableView.EnableViewState = True
AddHandler grdControl.ItemDataBound, AddressOf grdControl_ItemDataBound
AddHandler grdControl.ItemCommand, AddressOf grdControl_ItemCommand
AddHandler grdControl.NeedDataSource, AddressOf grdControl_needDataSource
RadGrid的ItemCommand事件如下
Protected Sub grdControl_ItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs)
If e.CommandName = "Edit" Then
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = e.Item
Dim Labelrow_ID As String = TryCast(item.FindControl("lbl1"), Label).Text
'Dim str As String = (DirectCast(item.DataItem, DataRowView))("emp_id").ToString()
item.BackColor = Drawing.Color.Pink
ElseIf e.CommandName = "UpdateAll" Then
For Each editedItem As GridEditableItem In grdControl.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)
SqlDataSource1.UpdateCommand = String.Format("Update Customers SET ContactName='{0}' WHERE CustomerID='{1}'", newValues("ContactName"), editedItem.GetDataKeyValue("CustomerID").ToString())
SqlDataSource1.Update()
editedItem.Edit = False
Next
End If
End If
End Sub
我希望存储所有已编辑行的值,以便可以执行批量编辑。