绑定到数据表时如何设置gridview列宽 [英] How to Set a gridview column width when binding to a datatable

查看:26
本文介绍了绑定到数据表时如何设置gridview列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将表格绑定到 asp.net 中的 gridview

I am binding a table to a gridview in asp.net as such

grdIssues.DataSource = mdtIssues;

grdIssues.DataBind();

问题是我无法控制列宽,asp.net 似乎自己决定了每列的宽度.方法如

The problem is I cannot then control the column width, asp.net seems to decided on it's own what width each column should be. Methods such as

 grdIssues.Columns[0].ItemStyle.Width = 100;
 grdIssues.Columns[1].ItemStyle.Width = 100;

不起作用,因为列是动态创建的.我不敢相信没有办法做到这一点,除非手动创建每一列并填充每一行.

don't work because the columns are created dynamically. I cannot believe there isn't a way to do this short of manually creating each column and filling each row.

推荐答案

您不必手动创建列来设置它们的宽度,您可以这样做

You dont have to manually create the columns to set them the width, you can do this

 foreach (DataControlField column in OrdersGV.Columns)
    {
      column.ItemStyle.Width = Unit.Pixel(100);
    }

这篇关于绑定到数据表时如何设置gridview列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆