如何为动态数据设置网格视图列宽 [英] How to set Grid view column width for dynamic data
本文介绍了如何为动态数据设置网格视图列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为动态数据设置网格视图列宽
这是我的代码,它显示错误..请任何人给我解决方案或其他方法。
受保护 void Gridname_RowDataBound( object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Gridname.Columns [ 1 ]。ItemStyle.Width = 10 跨度>;
Gridname.Columns [ 2 ]。ItemStyle.Width = 40 ;
}
}
然后显示错误
索引超出范围。必须是非负数且小于集合的大小。
参数名称:index
解决方案
看看这里:如何:动态设置GridView Web服务器控件列宽度[ ^ ]
using ItemStyle-width属性。
示例:
< asp:templatefield headertext =Questionitemstyle-width =500pxsortexpression =question>
< itemtemplate>
<%#Eval(question)%>
How to set Grid view column width for dynamic data
This is my code it''s showing error..please any one give me the solution or other method.
protected void Gridname_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Gridname.Columns[1].ItemStyle.Width = 10;
Gridname.Columns[2].ItemStyle.Width = 40;
}
}
then its showing error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
解决方案
Have a look here: How to: Set GridView Web Server Control Column Width Dynamically [^]
using ItemStyle-width property.
Example:
<asp:templatefield headertext="Question" itemstyle-width="500px" sortexpression="question">
<itemtemplate>
<%# Eval("question")%>
这篇关于如何为动态数据设置网格视图列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文