GridView列宽和换行 [英] GridView Column Width and Wrap

查看:68
本文介绍了GridView列宽和换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有UnBound GridView-C#ASP.Net,正在通过查询刷新它.
我有以下代码-

Hello,

I have UnBound GridView - C# ASP.Net and I am refreshing this by query.
I have below code -

SqlDataAdapter adp = new SqlDataAdapter("Select Entry_Date, Emp_Name, Qunatity, Comments From Activity_Master", SqlCon);
System.Data.DataTable dt = new System.Data.DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();



我想设置评论"列的列宽"为50,并希望弯曲.



I want to set Column width = 50 of "Comments" column and want Warp.

GridView1.Columns[3].ItemStyle.Width = 50;
      GridView1.Columns[3].ItemStyle.Wrap = true;



这给了我下面的错误.



This gives me below error.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index



如何解决这个问题.请帮忙.



How do resolve this. Please help.

推荐答案



绑定网格后,尝试设置列宽和环绕样式.
使用此流程:
Hi,

Try setting your column width and wrapping style after binding the grid.
use this flow:
if(!IsPostBack){
   SqlDataAdapter adp = new SqlDataAdapter("Select Entry_Date, Emp_Name, Qunatity,             
        Comments From Activity_Master", SqlCon);
   System.Data.DataTable dt = new System.Data.DataTable();
   adp.Fill(dt);
   GridView1.DataSource = dt;
   GridView1.DataBind();
}
GridView1.Columns[3].ItemStyle.Width = 50;
GridView1.Columns[3].ItemStyle.Wrap = true;



一切顺利.



All the best..


这篇关于GridView列宽和换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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