How can i sort the data in gridview control in asp.net? I use PageLoad() { .... DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter(qry, con); ad.Fill(ds); GridView1.DataSource = ds.Tables[0];
GridView1.DataBind(); GridView1.Sort("r_1", SortDirection.Ascending);
} but it give me error
"The GridView 'GridView1' fired event Sorting which wasn't handled" why this.,,,also i set AllowSorting to "True"....
|
| Author: mahalakshmi 05 Jul 2008 | Member Level: Gold | Rating: Points: 6 |
use it as a sample ,apply ur concept
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//string s = GridView1.SortExpression;
//e.SortExpression = s;
SqlDataAdapter da1 = new SqlDataAdapter ("Select * from product",con);
DataTable dt = new DataTable();
da1.Fill(dt);
DataView dv = new DataView(dt);
//dv.Sort
// GridView1.DataSource = dv.Sort;
//GridView1.DataBind();
dv.Sort = e.SortExpression + " " + "ASC";
GridView1.DataSource = dv;
GridView1.DataBind();
}
|
| Author: sandeep 07 Jul 2008 | Member Level: Gold | Rating: Points: 2 |
as you drag and drop the grid view there is option for sorting by clicking(enable) that option you can get your sorted grid view..............
|