J
JohnE
Hello. I have finally gotten the gridview to sort and page. But what I am
wondering is there a way to reverse the sort from what was originally done?
By that, if the user clicked the column header 'Name' it would sort (ASC) by
that column. If the user clicked on 'Name' again, the column would sort DESC
by that column. I also have an up arrow and down arrow that can be used to
show the column being sorted and in what direction. Where in code and how
would those be displayed? Here is the code that I have for the paging and
sorting. I was keeping it simple but it might be time to turn it up some.
private DataView bindgrid()
{
string connStr =
ConfigurationManager.ConnectionStrings["ProteusConnectionString"].ConnectionString;
string sql = "SEL_FillChangeRequestListGridView";
SqlDataAdapter sqlDa = new SqlDataAdapter(sql,connStr);
DataSet ds = new DataSet();
sqlDa.Fill(ds);
DataView dv = new DataView();
if (ViewState["sortExpr"] != null)
{ dv = new DataView(ds.Tables[0]);
dv.Sort = (string)ViewState["sortExpr"];
}
else
dv = ds.Tables[0].DefaultView;
return dv;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataView dv = new DataView();
dv = bindgrid();
GridView1.DataSource = dv;
GridView1.DataBind();
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState["sortExpr"] = e.SortExpression;
GridView1.DataSource = bindgrid();
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = bindgrid();
GridView1.DataBind();
}
I am a relatively new at all this coming from Access (VBA) to working on
webapps. So far I would say it is a great learning experience and wish I got
into it long ago.
Thanks... John
wondering is there a way to reverse the sort from what was originally done?
By that, if the user clicked the column header 'Name' it would sort (ASC) by
that column. If the user clicked on 'Name' again, the column would sort DESC
by that column. I also have an up arrow and down arrow that can be used to
show the column being sorted and in what direction. Where in code and how
would those be displayed? Here is the code that I have for the paging and
sorting. I was keeping it simple but it might be time to turn it up some.
private DataView bindgrid()
{
string connStr =
ConfigurationManager.ConnectionStrings["ProteusConnectionString"].ConnectionString;
string sql = "SEL_FillChangeRequestListGridView";
SqlDataAdapter sqlDa = new SqlDataAdapter(sql,connStr);
DataSet ds = new DataSet();
sqlDa.Fill(ds);
DataView dv = new DataView();
if (ViewState["sortExpr"] != null)
{ dv = new DataView(ds.Tables[0]);
dv.Sort = (string)ViewState["sortExpr"];
}
else
dv = ds.Tables[0].DefaultView;
return dv;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataView dv = new DataView();
dv = bindgrid();
GridView1.DataSource = dv;
GridView1.DataBind();
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState["sortExpr"] = e.SortExpression;
GridView1.DataSource = bindgrid();
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender,
GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = bindgrid();
GridView1.DataBind();
}
I am a relatively new at all this coming from Access (VBA) to working on
webapps. So far I would say it is a great learning experience and wish I got
into it long ago.
Thanks... John