我的asp.net - vb.net页面中有两个网格,其autogeneratecolumn设置为true。我绑定了列相同但数据不同的两个网格。现在,我想像在grid1中一样在grid2中设置列的宽度。有人能帮我这个忙吗?我尝试在后台代码中设置为:
Private Sub grid2_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles grid2.RowDataBound
For i = 0 To grid1.Rows(0).Cells.Count - 1
e.Row.Cells(i).Width = grid1.HeaderRow.Cells(i).Width
Next
End Sub但是grid1.HeaderRow.Cells(i).Width给我的值是0。
发布于 2020-08-08 22:43:22
尝试在Gridview的RowCreated事件上编写代码,如下所示:
Private Sub grid2_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles grid2.RowCreated
For i = 0 To grid1.Rows(0).Cells.Count - 1
e.Row.Cells(i).Width = grid1.HeaderRow.Cells(i).Width
} https://stackoverflow.com/questions/63315668
复制相似问题