C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







how to sort GridView data?


Posted Date: 05 Jul 2008      Total Responses: 2

Posted By: Lalit...wait for ANS       Member Level: Gold     Points: 1


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"....





Responses

Author: mahalakshmi    05 Jul 2008Member Level: GoldRating:     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 2008Member Level: GoldRating:     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..............


Post Reply
You must Sign In to post a response.
Next : Controls are in Disabled mode in toolbax
Previous : datagrid.sort () is not working
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

accuconference

Contact Us    Privacy Policy    Terms Of Use