如何在不导致视图状态错误的情况下向数据绑定gridview添加行?
我正在尝试向我的数据绑定gridview添加行分组行。它在第一个响应时工作正常,但在回发时我得到了“无法加载视图状态”错误。
GridView的RowDataBound事件有代码:
Private Sub AddGroupingRow(ByRef eRow As GridViewRow, ByVal Css As String, ByVal ColSpan As Integer, ByVal Txt As String)
Dim cell As New TableCell()
cell.ColumnSpan = ColSpan
cell.CssClass = "Spacing FieldCell"
cell.Text = Txt
Dim row As New GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal)
row.CssClass = Css
row.Cells.Add(cell)
Dim tbl As Table
tbl = eRow.Parent
tbl.Rows.AddAt(eRow.RowIndex + 1, row)
End Sub
Private Prev_Client_ID As Integer = -1
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim dr As Data.DataRowView = TryCast(e.Row.DataItem, Data.DataRowView)
If dr IsNot Nothing AndAlso dr.Row.RowState <> Data.DataRowState.Added Then
Dim Client_ID As Integer = dr.Item("Client_ID")
If Client_ID <> Prev_Client_ID Then AddGroupingRow(e.Row, "Group", 8, dr.Item("Client_Name"))
Prev_Client_ID = Client_ID
End If
End If
End Sub
我知道在数据源上创建分组行更容易,但是从这段代码中得出,我想为站点的其他网格创建一些基础。
没有找到相关结果
已邀请:
2 个回复
肺鬼耙扮群
掸牛浓疗
它仍然对列进行分组,但以另一种方式,并且更加友好。我可以使用rowpans并将单元格变为不可见,但它会更难保持。此外,当用户将鼠标移到它上面时,我需要绘制线条,并且会有很多行会阻碍。