求助DataGridView 如何自定义排序
1个回答
展开全部
//AllowSorting="True" OnSorting="gvStore_Sorting"
protected void gvStore_Sorting(object sender, GridViewSortEventArgs e)
{
//双向排序
if (ViewState["sort"] == null)
{
ViewState["sort"] = "ASC";//默认升序
}
else
{
if (ViewState["sort"].ToString() == "ASC")
{
ViewState["sort"] = "DESC";
}
else
{
ViewState["sort"] = "ASC";
}
}
//重新绑定数据
SqlConnection conn = new SqlConnection(DbConn.connStr);
SqlDataAdapter sda = new SqlDataAdapter("select * from store", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);//数据试图
//排序条件
dv.Sort = e.SortExpression + " " + ViewState["sort"].ToString();
//设置数据源
gvStore.DataSource = dv;
gvStore.DataBind();
}
protected void gvStore_Sorting(object sender, GridViewSortEventArgs e)
{
//双向排序
if (ViewState["sort"] == null)
{
ViewState["sort"] = "ASC";//默认升序
}
else
{
if (ViewState["sort"].ToString() == "ASC")
{
ViewState["sort"] = "DESC";
}
else
{
ViewState["sort"] = "ASC";
}
}
//重新绑定数据
SqlConnection conn = new SqlConnection(DbConn.connStr);
SqlDataAdapter sda = new SqlDataAdapter("select * from store", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
DataView dv = new DataView(ds.Tables[0]);//数据试图
//排序条件
dv.Sort = e.SortExpression + " " + ViewState["sort"].ToString();
//设置数据源
gvStore.DataSource = dv;
gvStore.DataBind();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询