c# - ASP.NET C# - 维护 DataGrid 列宽
问题描述
我有一个数据源,每次运行时它可能有不同数量的列。我尝试使用 RowDataBound 事件根据标题设置每列的大小(如下所示)。
问题是,如果有很多列,宽度会缩小。不管我有多少列,有没有办法强制这个宽度?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int j = 0; j < NoOfColumns; j++)
{
string row = e.Row.Cells[j].Text;
if (row.Contains("Date"))
{
e.Row.Cells[j].Width = new Unit(150);
}
else if (row.Contains("Transaction"))
{
e.Row.Cells[j].Width = new Unit(250);
}
else if (row.Contains("+"))
{
e.Row.Cells[j].Width = new Unit(300);
}
else if (row.Contains("Balance"))
{
e.Row.Cells[j].Width = new Unit(400);
}
}
}
解决方案
推荐阅读
- c# - 有什么更优雅的方式来检查和分配字符串排列?
- r - cmdstanR:从 stan 模型拟合中提取绘图
- javascript - Instagram 从电脑上传视频
- javascript - 将现有 React 应用程序的客户端渲染转换为服务器端渲染
- adsense - Adsense 不适用于子域,403 错误
- python - 将 TensorFlow 1.0 代码转换为 2.0 版本
- webassembly - WASI 与 Web-Assembly
- java - 如何将 MS Access 数据库数据连接到 Net-beans java 程序
- python - matlab有没有使用条件连接数组的功能?
- eclipse - BirtDateTime.addDay 在新年前夜返回错误的年份