在 ASP.NET 4.0 GridView 中,是否可以同时在编辑模式下拥有多行?
我在属性中使用编辑模式控制行:
Private Property Editing As List(Of Integer)
Get
If ViewState("Editing") Is Nothing Then ViewState("Editing") = New List(Of Integer)
Return CType(ViewState("Editing"), List(Of Integer))
End Get
Set(value As List(Of Integer))
ViewState("Editing") = value
End Set
End Property
当用户点击编辑按钮时填充它:
Protected Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Edit" Then
Dim row = CType(CType(e.CommandSource, LinkButton).NamingContainer, GridViewRow)
Editing.Add(row.RowIndex)
End If
End Sub
并在 RowDataBound 事件中手动更改 RowState 属性:
Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Editing.Contains(e.Row.RowIndex) Then
Then e.Row.RowState = DataControlRowState.Edit
End If
End If
End Sub
但它不起作用,行正在以正常状态呈现......任何想法?
编辑 2:财产
MultipleEditGridView.vb:
Namespace ClubeCheckIn.UI
Public Class MultipleEditGridView
Inherits GridView
Protected Property IsRowInEditMode(rowIndex As Int32) As Boolean
Get
If ViewState("GridRowEditIndices") Is Nothing Then
Return False
Else
Dim indices = DirectCast(ViewState("GridRowEditIndices"), List(Of Int32))
Return indices.Contains(rowIndex)
End If
End Get
Set(value As Boolean)
If ViewState("GridRowEditIndices") Is Nothing Then
ViewState("GridRowEditIndices") = New List(Of Int32)
End If
Dim indices = DirectCast(ViewState("GridRowEditIndices"), List(Of Int32))
indices.Remove(rowIndex)
indices.Add(rowIndex)
End Set
End Property
End Class
End Namespace
网络配置:
<controls>
<add tagPrefix="clube" namespace="ClubeCheckIn.UI" />
</controls>
ASPX:
<clube:MultipleEditGridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtEdit" runat="server" Visible="<%# IsRowInEditMode(Container.DataItemIndex) %>" />
</ItemTemplate>
</Columns>
</clube:MultipleEditGridView>
错误:
错误:BC30451:未声明“IsRowInEditMode”。由于保护级别,它可能无法访问