在gridview错误中排序 [英] Sorting in gridview error
本文介绍了在gridview错误中排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在gridview记录中如下
in gridview record as follows
slipdate slipno product Desc status
21.08.2018 456 A yes New
22.08.2018 123 B yes New
23.08.2018 145 C yes New
22.08.2018 557 D yes New
在运行模式下,当我点击网格视图中的单据时,排序显示错误如下
无法将'system.data.dataset'类型的对象转换为'system.data.datatable'类型
我的上面代码在gridview排序代码中的错误是什么。
我必须做出哪些更改
我尝试过:
in the run mode when i click the slip no in gridview for sorting shows error as follows
unable to cast object of type 'system.data.dataset' to type 'system.data.datatable'
what is the mistake in my above code in gridview sorting code.
what changes i have to made
What I have tried:
public void refreshdata()
{
String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("select * from [transact].[transaction_item] con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
grdRpt.DataSource = ds;
grdRpt.DataBind();
ViewState["dirState"] = ds;
ViewState["sortdr"] = "Asc";
}
protected void grdRpt_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtrslt = (DataTable)ViewState["dirState"];
if (dtrslt.Rows.Count > 0)
{
if (Convert.ToString(ViewState["sortdr"]) == "Asc")
{
dtrslt.DefaultView.Sort = e.SortExpression + " Desc";
ViewState["sortdr"] = "Desc";
}
else
{
dtrslt.DefaultView.Sort = e.SortExpression + " Asc";
ViewState["sortdr"] = "Asc";
}
grdRpt.DataSource = dtrslt;
grdRpt.DataBind();
}
}
推荐答案
正在成对工作,2乘2,你有1,这里缺少第二个:
" are working in pairs, 2 by 2, you have 1 here, the second is missing:
SqlCommand cmd = new SqlCommand("select * from [transact].[transaction_item] con);
^
这篇关于在gridview错误中排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文