100分急紧求助,数据绑定问题
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GridView1.EditIndex = -1;
if (ViewState["sortColumn"].ToString() == e.SortExpression.ToString())
{
if ("ASC" == ViewState["sortDirection"].ToString())
{
ViewState["sortDirection"] = "DESC";
}
else
{
ViewState["sortDirection"] = "ASC";
}
}
else
{
ViewState["sortColumn"] = e.SortExpression.ToString();
ViewState["sortDirection"] = "ASC";
}
orderbind(ViewState["sortColumn"].ToString(), ViewState["sortDirection"].ToString());
}
//===========================================================
void orderbind(string SortPression,string SortDirction)//绑定datagrid
{
string sql = "select * from nclass where class_mark=0 order by " + SortPression + " " + SortDirction;
obj.New();
obj.binddatagrid(sql, GridView1);
obj.Close();
}
//===========================================================
public void binddatagrid(string sql, GridView dg)
{
if(con.State==ConnectionState.Closed)
{
Open();
}
ds=getdataset(sql);
dg.DataSource=ds.Tables[0].DefaultView;
//dg.DataBinding();
dg.DataBind();
}
//===========================================================
public DataSet getdataset(string sql)
{
if(con.State==ConnectionState.Closed)
{
Open();
}
adp=new OleDbDataAdapter(sql,con);
ds=new DataSet();
adp.Fill(ds,"ds");
return ds;
}
现在的问题是:当string sql = "select * from nclass where class_mark=0 order by " + SortPression + " " + SortDirction;时getdataset()中的adp.Fill(ds,"ds");这句出错,当string sql = "select * from nclass where class_mark=0 "时是正确的,说明数据绑定函数没有问题,但遇到排序时就出错了,有可能是GridView1_Sorting()或orderbind出问题了,请高手帮忙指点一下,小弟忙火了半天了,费解呀。55555555555。其实我就是要实现一个gridview的多列排序问题。