System.IndexOutOfRangeException:找不到列 [英] System.IndexOutOfRangeException: Cannot find column
本文介绍了System.IndexOutOfRangeException:找不到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在实现gridview排序,这是用户控件的一部分.下面的代码给我Indexoutofrange错误.
I am implementing gridview sorting which is part of a user control. Below code gives me Indexoutofrange error.
错误消息位于
dtView.Sort = strSort;
错误消息:
System.IndexOutOfRangeException:找不到列TEXT_COUNTY_ID.
System.IndexOutOfRangeException: Cannot find column TEXT_COUNTY_ID.
有人能指出我在做什么错吗?
Can anyone point out what I am doing wrong?
protected void SortGridData_Hkl(Object sender, GridViewSortEventArgs e)
{
GridView _dgd_work_onoff = (GridView)Page.FindControl("bodyuc$dgd_work_onoff");
DataSet dstemp;
DataView dtView;
if (ViewState["dsfetchResults"] != null)
{
dstemp = (DataSet)ViewState["dsfetchResults"];
string strSortOrder = ViewState["SortOrder"].ToString();
if (strSortOrder == "DESC")
{
strSortOrder = "ASC";
ViewState["SortOrder"] = strSortOrder;
}
else
{
strSortOrder = "DESC";
ViewState["SortOrder"] = strSortOrder;
}
string strSort = e.SortExpression.ToString() + " " + strSortOrder;
ViewState["SortString"] = strSort;
dtView = dstemp.Tables[0].DefaultView;
dtView.Sort = strSort;
if (dtView.Count != 0)
{
if (_dgd_work_onoff != null)
{
_dgd_work_onoff.DataSource = dtView;
_dgd_work_onoff.DataBind();
}
}
}
'dsfetchResults'应该包含数据库中的数据.
'dsfetchResults' is suppose to contain the data from the database.
推荐答案
找到解决方案.列名称与数据库列的名称不同.
Got the solution. The column name was different from that of the database column.
这篇关于System.IndexOutOfRangeException:找不到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文