开发者

System.IndexOutOfRangeException: Cannot find column [duplicate]

开发者 https://www.devze.com 2023-02-26 07:40 出处:网络
This question already has an answer here: System.IndexOutOfRangeException: Cannot find column (1 answer)
This question already has an answer here: System.IndexOutOfRangeException: Cannot find column (1 answer) Closed 10 years ago.

I am implementing girdview sorting, which is part of a user control. The code below gives me Indexoutofrange error.

The error message is:

dtView.Sort = strSort;
Errormessage: System.IndexOutOfRangeException: Cannot find column TEXT_COUNTY_ID.

Can anyone point out what I am doing wrong?

Really appreciate your help.

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 is supposed to contain the data from the database.


I fixed it. the issue was that I used a different column name in the design (.aspx) than the one in the database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号