我创建了一个动态网格视图,并通过电子邮件发送。但除标题文本外,所有工作都有效。我似乎找不到如何定义标题文本。
我的 sqlCommand 显示 4 列,但是当我使用时:
LabelTest.Text = "Init Count: " +grd.Columns.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 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 语句仅将我的列彼此分开。除此之外,我没有指定任何列左右来设置标题文本。