0

在 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”。由于保护级别,它可能无法访问

4

2 回答 2

1

我很确定GridView在编辑模式下不支持多行。

作为一种解决方法,您可以将ItemTemplate用于两种状态(fe aLabel和 a TextBox)。然后,您可以使用EditMode带有RowIndexas 参数的属性。您可以将行以编辑模式存储在ViewState.

(未测试)

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

您可以直接从标记中调用它, fe 用于编辑控件:

Visible='<%# IsRowInEditMode(Container.DataItemIndex) %>
于 2012-12-27T22:22:03.137 回答
0

你可以用这个对面糊有用...

   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
于 2013-04-05T08:01:34.627 回答