Click here to Skip to main content
15,908,581 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionGridView Sorting Problem Pin
vickyshah12-Jul-07 3:45
vickyshah12-Jul-07 3:45 
AnswerRe: GridView Sorting Problem Pin
Sathesh Sakthivel12-Jul-07 3:48
Sathesh Sakthivel12-Jul-07 3:48 
GeneralRe: GridView Sorting Problem Pin
vickyshah12-Jul-07 3:52
vickyshah12-Jul-07 3:52 
GeneralRe: GridView Sorting Problem Pin
Not Active12-Jul-07 4:00
mentorNot Active12-Jul-07 4:00 
GeneralRe: GridView Sorting Problem Pin
Sathesh Sakthivel12-Jul-07 4:00
Sathesh Sakthivel12-Jul-07 4:00 
GeneralRe: GridView Sorting Problem Pin
Christian Graus12-Jul-07 4:00
protectorChristian Graus12-Jul-07 4:00 
GeneralRe: GridView Sorting Problem Pin
Not Active12-Jul-07 4:12
mentorNot Active12-Jul-07 4:12 
AnswerRe: GridView Sorting Problem Pin
Steve Echols12-Jul-07 16:32
Steve Echols12-Jul-07 16:32 
You're getting an infinite loop because calling GridView1.Sort will fire the GridView1_Sorting event (I'm sure you figured that out aleady)

I think GridView will only sort automatically if you're using one of the new DataSource providers, like SqlDataSource, XmlDataSource, ObjectDataSource, etc. (I could be wrong about that, but so far that's been my experience).

You could try something like:

private void FillGrid( string sortExpression, SortDirection sortDir )
{
   string sort = sortExpression + " " + (sortDir == SortDirection.Descending ? "desc" : "" );

   DataTable dt = GetDataTableFromSomewhere();
   DataView dv = new DataView(dt, "", sort, DataViewRowState.CurrentRows );
   GridView1.DataSource = dv;
   GridView1.DataBind();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
   FillGrid(e.SortExpression, e.SortDirection);
}


Viewstate could become an issue doing it this way. I typically disable view state on grids though, but then you have to work around a bunch of other issues.



- S
50 cups of coffee and you know it's on!

QuestionCheckbox in Datagrid Pin
Kurian_Kurian12-Jul-07 3:22
Kurian_Kurian12-Jul-07 3:22 
AnswerRe: Checkbox in Datagrid Pin
Paul Conrad13-Jul-07 12:18
professionalPaul Conrad13-Jul-07 12:18 
QuestionCheckboxes in gridview Pin
samerh12-Jul-07 2:30
samerh12-Jul-07 2:30 
AnswerRe: Checkboxes in gridview Pin
Christian Graus12-Jul-07 2:45
protectorChristian Graus12-Jul-07 2:45 
GeneralRe: Checkboxes in gridview Pin
samerh12-Jul-07 3:26
samerh12-Jul-07 3:26 
GeneralRe: Checkboxes in gridview Pin
Christian Graus12-Jul-07 4:55
protectorChristian Graus12-Jul-07 4:55 
QuestionGridView Pin
.NET- India 12-Jul-07 2:20
.NET- India 12-Jul-07 2:20 
AnswerRe: GridView Pin
Sathesh Sakthivel12-Jul-07 2:28
Sathesh Sakthivel12-Jul-07 2:28 
GeneralRe: GridView Pin
Not Active12-Jul-07 2:52
mentorNot Active12-Jul-07 2:52 
GeneralRe: GridView Pin
Pete O'Hanlon12-Jul-07 3:12
mvePete O'Hanlon12-Jul-07 3:12 
GeneralRe: GridView Pin
Not Active12-Jul-07 3:34
mentorNot Active12-Jul-07 3:34 
GeneralRe: GridView Pin
Pete O'Hanlon12-Jul-07 3:40
mvePete O'Hanlon12-Jul-07 3:40 
GeneralRe: GridView Pin
Not Active12-Jul-07 3:46
mentorNot Active12-Jul-07 3:46 
GeneralRe: GridView Pin
Sandeep Akhare12-Jul-07 3:46
Sandeep Akhare12-Jul-07 3:46 
GeneralRe: GridView Pin
Sathesh Sakthivel12-Jul-07 3:52
Sathesh Sakthivel12-Jul-07 3:52 
GeneralRe: GridView Pin
Sathesh Sakthivel12-Jul-07 4:02
Sathesh Sakthivel12-Jul-07 4:02 
AnswerRe: GridView Pin
Not Active12-Jul-07 2:53
mentorNot Active12-Jul-07 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.