Asp.net gridview - 操纵列宽 [英] Asp.net gridview - manipulate column widths
问题描述
您好,
我有一个WCF服务,它将数据集返回给asp.net Web客户端。然后,客户端使用传递的数据集作为其Gridview显示的源。但是,我希望能够在构建网格时控制每列的宽度,而不是仅允许应用默认列宽。这可以通过逗号分隔的字符串(例如20,100,50,50,10)来实现,其中每个数字代表相应列中的像素数(col1 = 20像素,Col2 = 100像素,Col3 = 50像素等...)
是否可以这样做,如果是这样,有人可以解释如何并可能给我一个例子吗?
谢谢
Pat
我的尝试:
搜索网页,
专家交换
Hello,
I have a WCF Service which returns a dataset to the asp.net web client. The client then uses the passed dataset as the source for it's Gridview display. However rather than just allowing the default columns widths to be applied I want to be able to control the width of each column at the time the grid is being built. This might be achieved by a comma delimited string (eg 20,100,50,50,10) where each number represents the number of pixels in the corresponding column (col1=20 pixels, Col2=100 pixels, Col3=50 pixels etc..)
Is it possible to do this and if so can someone explain how and possibly give me an example ?
thanks
Pat
What I have tried:
Searching the web,
experts exchange
推荐答案
如果您正在使用TemplateFields&绑定在.aspx文件中,您可以使用以下内容控制列宽;
If you are using TemplateFields & Binding in your .aspx file you can control the column width using the following;
<asp:templatefield>
<headerstyle width="10%" />
<itemtemplate>
<asp:label id="lblField" runat="server" text="<%# DataBinder.Eval(Container, "DataItem.ColumnName") %>"><asp:label>
</itemtemplate>
</asp:templatefield>
如果你在背后的代码中这样做,那简直就是在绑定后得到网格视图的问题&根据需要设置列宽
亲切的问候
If you are doing it in the code behind it is simply a matter of getting the grid view after binding & setting the column widths as required
Kind Regards
这篇关于Asp.net gridview - 操纵列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!