asp.net - 设置 Gridview 列宽
问题描述
我的 asp.net 页面中有两个网格 - vb.net,autogeneratecolumn 设置为 true。我绑定了列相同但数据不同的两个网格。现在我想在grid2中设置列的宽度,就像在grid1中一样。任何人都可以帮助我。我试图在后面的代码中设置为:
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 作为价值。
解决方案
尝试在 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
}
推荐阅读
- google-cloud-platform - GCP 中的服务帐户、角色和访问范围有什么区别?
- makefile - 如果未设置环境变量,会导致 makefile 出错?
- sql - 无法使用 json_build_object 从 postgreSQL 查询创建大型 json 对象
- python - Django 无法搜索“方法不允许”
- c - 在构建时解决符号冲突
- r - 用R中该矩阵中不同行的值填充矩阵中的缺失值
- python - 从 tkinter gui 接收数据并在列表之间执行数学运算
- powerbi - 是否有特定的方法可以在 PowerBI 的列中有条件地添加?
- r - 在字符串之后提取第 n 次出现
- javascript - 为什么改变一个数组会以某种方式改变另一个?