请参阅下面的代码,我尝试通过调用微软vs 2008提供的函数对网格视图数据进行排序,但分页完成但排序过程不起作用,请告诉我应该在哪里我改变了下面的代码,是的,我把网格视图更新为刑罚,是否有更新刑罚的问题?如何排序gridview数据
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
showData();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("showData", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0] != null)
{
ds.Tables[0].DefaultView.Sort = e.SortExpression + " " + sortType(e.SortDirection);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
catch (Exception ex)
{
Label1.Text = ex.ToString();
}
}
private string sortType(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "DESC";
break;
case SortDirection.Descending:
newSortDirection = "ASC";
break;
}
return newSortDirection;
}
是我没有AllowSorting =“true”和OnSorting =“GridView1_Sorting” – Dadu
我使用分页和排序在同一网格视图是否有可能在asp.net – Dadu