Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GridView.Columns[index].HeaderText抛出“索引超出范围”错误_C#_.net_Asp.net - Fatal编程技术网

C# GridView.Columns[index].HeaderText抛出“索引超出范围”错误

C# GridView.Columns[index].HeaderText抛出“索引超出范围”错误,c#,.net,asp.net,C#,.net,Asp.net,页眉计数正确 AutoGenerateColumns:Flase/True我两个都试过了 如果删除gvOff.Columns[index].HeaderText部分,GridView工作正常,但当我删除gvOff.Columns[0].HeaderText时,会出现异常错误 你能帮个忙吗,我解决不了。如果您需要更多信息,请通知我 编辑: 坚持住!我对HeaderText部分进行了注释并进行了测试 int i=gvover.Columns.Count 我发现计数为0,即使列使用数据绑定打印出来。。

页眉计数正确

AutoGenerateColumns:Flase/True我两个都试过了

如果删除gvOff.Columns[index].HeaderText部分,GridView工作正常,但当我删除gvOff.Columns[0].HeaderText时,会出现异常错误

你能帮个忙吗,我解决不了。如果您需要更多信息,请通知我

编辑:


坚持住!我对HeaderText部分进行了注释并进行了测试

int i=gvover.Columns.Count

我发现计数为0,即使列使用数据绑定打印出来。。。为什么?

注意:在这种情况下,AutoColumn设置为true。我想我得编辑这个专栏了
数据表中的名称。

已解决。。。。我刚刚使用SQL查询别名更改了列名,这反映在我的应用程序中。例如:

    gvOff.DataSource = o.ViewData(dCity.SelectedValue);
    gvOff.DataBind();
    gvOff.Columns[0].HeaderText = "ZZZZZZZZ";
    gvOff.Columns[1].HeaderText = "YYYYYYYY";
    gvOff.Columns[2].HeaderText = "XXXXXXXX";

是否确定数据源有效且列计数>0?请稍候!我对HeaderText部分进行了注释并进行了测试:int I=gvOffer.Columns.Count;我发现计数为0,即使列使用数据绑定打印出来。。。为什么?
SELECT orderID AS [XXXXX], name AS [YYYYY] FROM TableName