关于绑定gridview的升序降序有关问题,为嘛只能升序没法降序呢?有代码
关于绑定gridview的升序降序问题,为嘛只能升序没法降序呢?有代码
public void DataBind(string sortField)
{
string pro_manager = Session["realname"].ToString();
string strSql = "select a.*,b.company from unconfirmed_quotes a,customer_info b ";
strSql += " where a.pro_manager='" + pro_manager + "' and a.customer=b.realname";
using (MySqlConnection conn = new MySqlConnection("database=test;data source=127.0.0.1;user id=root;password=root;port=3306") )
{
conn.Open();
MySqlDataAdapter adt = new MySqlDataAdapter(strSql, conn);
DataSet ds = new DataSet();
adt.Fill(ds);
DataView dvw = ds.Tables[0].DefaultView;
if (!string.IsNullOrEmpty(sortField))
dvw.Sort = sortField;
this.GridView_UnconfirmedQuotes.DataSource = dvw.Table;
this.GridView_UnconfirmedQuotes.DataBind();
}
}
//public void bind()
//{
// string pro_manager = Session["realname"].ToString();
// string strSql = "select a.*,b.company from unconfirmed_quotes a,customer_info b ";
// strSql += " where a.pro_manager='" + pro_manager + "' and a.customer=b.realname";
// MySqlConnection conn = new MySqlConnection("database=test;data source=127.0.0.1;user id=root;password=root;port=3306");
// conn.Open();
// MySqlDataAdapter adt = new MySqlDataAdapter(strSql, conn);
// DataSet ds = new DataSet();
// adt.Fill(ds);
// DataView view = ds.Tables[0].DefaultView;
// string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
// view.Sort = sort;
// GridView_UnconfirmedQuotes.DataSource = view;
// GridView_UnconfirmedQuotes.DataBind();
// conn.Close();
//}
protected void Unconfirm_Sorting(object sender, GridViewSortEventArgs e)
{
if (ViewState["SortField"].ToString() == e.SortExpression)
{
ViewState["SortField"] += " DESC";
}
else
ViewState["SortField"] = e.SortExpression;
DataBind(ViewState["SortField"].ToString());
//string sPage = e.SortExpression;
//if (ViewState["SortOrder"].ToString() == sPage)
//{
// if (ViewState["OrderDire"].ToString() == "Desc")
// ViewState["OrderDire"] = "ASC";
// else
// ViewState["OrderDire"] = "Desc";
//}
//else
//{
// ViewState["SortOrder"] = e.SortExpression;
//}
//bind();