G
Guest
i am able to allow the user to sort the columns of my datagrid, but only in
ascending order. is there a way to allow sorting in descending order? thanks
in advance.
private void Page_Load(object sender, System.EventArgs e)
{
string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCMD = new SqlCommand(sTODS);
sqlCMD.Connection = sqlConn;
sqlConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sqlCMD);
DataSet ds = new DataSet();
adapter.Fill(ds);
dgSearchResults.DataSource = ds.Tables[0];
int tableRowCount = ds.Tables[0].Rows.Count;
if (tableRowCount != 0)
{
DataView dv = new DataView();
dv=ds.Tables[0].DefaultView;
Page.Session.Add("DataViewOriginal",dv);
dgSearchResults.DataSource=dv;
dgSearchResults.DataBind();
dgSearchResults.Visible = true;
}
else
{
dgSearchResults.Visible = false;
}
}
private void dgSearchResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(Page.Session["DataViewOriginal"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOriginal"];
dv.Sort=e.SortExpression;
dgSearchResults.DataSource=dv; //assign the source
dgSearchResults.DataBind();
}
}
ascending order. is there a way to allow sorting in descending order? thanks
in advance.
private void Page_Load(object sender, System.EventArgs e)
{
string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCMD = new SqlCommand(sTODS);
sqlCMD.Connection = sqlConn;
sqlConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(sqlCMD);
DataSet ds = new DataSet();
adapter.Fill(ds);
dgSearchResults.DataSource = ds.Tables[0];
int tableRowCount = ds.Tables[0].Rows.Count;
if (tableRowCount != 0)
{
DataView dv = new DataView();
dv=ds.Tables[0].DefaultView;
Page.Session.Add("DataViewOriginal",dv);
dgSearchResults.DataSource=dv;
dgSearchResults.DataBind();
dgSearchResults.Visible = true;
}
else
{
dgSearchResults.Visible = false;
}
}
private void dgSearchResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(Page.Session["DataViewOriginal"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOriginal"];
dv.Sort=e.SortExpression;
dgSearchResults.DataSource=dv; //assign the source
dgSearchResults.DataBind();
}
}