|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to specify the sort column of a GridViewI use a GridView to display data , the datasource of my GridView is from a
ObjectDataSource. How can I specify the sort column? 1. Click on the grid in design view
2. Add an event handler for sort a) Click the events b) Add event for SortCommand (generally {gridname}_Sort) 3. In this event you will capture the SortExpression from e (event args) 4. Use this to create a DataView with an ASC or DESC filter Example private void grdReports_Sort(object source, DataGridSortCommandEventArgs e) { string sortExpression = Session["QueueSortExpression"].ToString(); string sortDirection = Session["QueueSortDirection"].ToString(); if (sortExpression != e.SortExpression) { sortExpression = e.SortExpression; sortDirection = "asc"; } else { if (sortDirection == "asc") sortDirection = "desc"; else sortDirection = "asc"; } Session["QueueSortExpression"] = sortExpression; Session["QueueSortDirection"] = sortDirection; DataView dv = (DataView) Session["sortedDV"]; StringBuilder builder = new StringBuilder(); builder.Append(sortExpression); builder.Append(" "); builder.Append(sortDirection); dv.Sort = builder.ToString(); //Bind BindForm(null); } -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA *************************** Think Outside the Box! *************************** "ad" wrote: > I use a GridView to display data , the datasource of my GridView is from a > ObjectDataSource. > How can I specify the sort column? > > > Thanks,
But I do'nt how to add event handler for sort (Setp2) Could you tell me more detail? Show quote "Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@comcast.netNoSpamM> ¼¶¼g©ó¶l¥ó·s»D:9488134F-288B-48E1-B2CE-4DDC6B0B4***@microsoft.com... > 1. Click on the grid in design view > 2. Add an event handler for sort > a) Click the events > b) Add event for SortCommand > (generally {gridname}_Sort) > 3. In this event you will capture the SortExpression from e (event args) > 4. Use this to create a DataView with an ASC or DESC filter > > Example > private void grdReports_Sort(object source, DataGridSortCommandEventArgs > e) > { > string sortExpression = Session["QueueSortExpression"].ToString(); > string sortDirection = Session["QueueSortDirection"].ToString(); > > if (sortExpression != e.SortExpression) > { > sortExpression = e.SortExpression; > sortDirection = "asc"; > } > else > { > if (sortDirection == "asc") > sortDirection = "desc"; > else > sortDirection = "asc"; > } > > Session["QueueSortExpression"] = sortExpression; > Session["QueueSortDirection"] = sortDirection; > > DataView dv = (DataView) Session["sortedDV"]; > > StringBuilder builder = new StringBuilder(); > builder.Append(sortExpression); > builder.Append(" "); > builder.Append(sortDirection); > > dv.Sort = builder.ToString(); > > //Bind > BindForm(null); > } > > > > -- > Gregory A. Beamer > MVP; MCP: +I, SE, SD, DBA > > *************************** > Think Outside the Box! > *************************** > > > "ad" wrote: > >> I use a GridView to display data , the datasource of my GridView is from >> a >> ObjectDataSource. >> How can I specify the sort column? >> >> >> |
|||||||||||||||||||||||