請參閱下面的代碼,我嘗試通過調用微軟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