使用 sqlCommand 更改动态 gridview 中的标题文本
我创建了一个动态网格视图,并通过电子邮件发送。但除了标题文本之外,所有内容都有效。我似乎找不到如何定义标题文本。
我的 sqlCommand 显示 4 列,但是当我使用:
LabelTest.Text = "Init Count: " +grd.Columns.Count;
它显示 Init Count: 0
所以我尝试执行 grd.Columns[0].HeaderText = "Something";
来设置标题文本,但是似乎没有任何作用。我也尝试将 0 更改为 3,4,5 但同样的问题。
错误是:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.Collections.ArrayList.get_Item(Int32 index) at..
有人有什么想法吗?谢谢。
编辑:我如何创建我的 gridview:
GridView grd = new GridView();
// Css style voor de gridview
grd.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
grd.GridLines = GridLines.None;
grd.RowStyle.HorizontalAlign = HorizontalAlign.Center;
grd.Columns[0].HeaderText = "Something"; //error
grd.Width = 600;
LabelTest.Text = "Init Count: " +grd.Columns.Count;
foreach (DataControlField field in grd.Columns)
{
field.ItemStyle.Width = Unit.Percentage(100 / grd.Columns.Count);
}
if (sendGrid != null)
{
grd.DataSource = sendGrid.ExecuteReader();
grd.DataBind();
}
sendGrid 是我在其中选择 4 列的 sqlCommand 的名称。
foreach 语句仅将我的列彼此分开一点。除此之外,我没有指定任何列等来设置标题文本。
I created a dynamic gridview which I send in an email. But all works except for the headertext. I can't seem to find how i can define the headertext.
My sqlCommand displays 4 columns, but when i use:
LabelTest.Text = "Init Count: " +grd.Columns.Count;
it shows, Init Count: 0
So i'm trying to do grd.Columns[0].HeaderText = "Something";
to set the headertext but nothing seems to work. I also tried changing the 0 to 3,4,5 but same problem.
The error is:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.Collections.ArrayList.get_Item(Int32 index) at..
Any ideas anyone? Thank you.
Edit: How i have created my gridview:
GridView grd = new GridView();
// Css style voor de gridview
grd.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
grd.GridLines = GridLines.None;
grd.RowStyle.HorizontalAlign = HorizontalAlign.Center;
grd.Columns[0].HeaderText = "Something"; //error
grd.Width = 600;
LabelTest.Text = "Init Count: " +grd.Columns.Count;
foreach (DataControlField field in grd.Columns)
{
field.ItemStyle.Width = Unit.Percentage(100 / grd.Columns.Count);
}
if (sendGrid != null)
{
grd.DataSource = sendGrid.ExecuteReader();
grd.DataBind();
}
sendGrid is the name of my sqlCommand in which I select 4 columns.
The foreach statement only sets my columns a bit more apart from each other. Other than that i'm not specifying any columns or so to set the headertext.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在使用
添加 Columns 设置其
属性,然后将其添加到 GridView。
If you are using the
to add Columns set its
property and then add it to the GridView.