将datagridview列宽设置为Web表单中的最大单元格 [英] set datagridview column width to largest cell in web form

查看:155
本文介绍了将datagridview列宽设置为Web表单中的最大单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到存储过程的数据网格,该存储过程从基础数据库中检索记录.

有很多列,我想将每列的宽度设置为最大.每列中最大值的长度.

另外,如果数据是数字值,我想在单元格内保持对齐.

如何使用ASP.NET 2和vb.Net在Web表单中实现此目标?

I have a datagrid which is linked to a stored procedure which retrieves records from a underlying database.

There are many columns and I want to size the width of each column to the max. length of the largest value in each column.

Also if the data is numeric I want to left justify within the cell.

How do I achieve this in a web form with ASP.NET 2 and vb.Net?

推荐答案

列很多,我想确定宽度每列的最大数量每列最大值的长度.


对于不应该换行的每一列,请将ItemStyle换行属性设置为false.
There are many columns and I want to size the width of each column to the max. length of the largest value in each column.


For each column, that shouldn''t wrap, set the ItemStyle wrap property to false.
<ItemStyle Wrap="False" />



如果数据是数字值,我想在单元格内对齐.


同样,您可以使用ItemStyle设置列的样式.
做这样的事情:



Also if the data is numeric I want to left justify within the cell.


Again, you can use ItemStyle to style the column.
Do something like this:

<ItemStyle CssClass="alignRight" />


CSS:


CSS:

.alignRight{text-align:right;}


Still no good. Perhaps the problem is with the data itself. It's a date time stamp eg 2010-07-26 11:01:52.000. Actually that's wrong as varchar variables are also wrapping. Here is the code that generates the grid.


 Collapse | Copy Code
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"  Font-Names="Arial" Font-Size="Small" AllowPaging="True" ItemStyle Wrap="False"

>
          <RowStyle BackColor="White" Wrap="True" />
How do I set nowrap for selected columns when the data comes from a stored procedure?


这篇关于将datagridview列宽设置为Web表单中的最大单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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