sorting a datagrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie

    #1

    sorting a datagrid

    Hello!

    I need help in making my datagrid sortable by clicking a column header.

    In the datagrid's property builder, Allow Sorting is checked. I am using a
    Bound column and it's Sort Expression is set to the same value as the Data
    Field value. But I dont know how to implement:

    private void dgResults_SortC ommand(object source,
    System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
    {

    }

    Please help.
  • Josema

    #2
    RE: sorting a datagrid

    Hi,

    How you fill the datagrid?, are you using a datatable?

    If you're using a datatable you can use this code:

    //When you get the data from (for instance :database)

    DataView dv = new DataView();
    dv=Yourdatatabl e.DefaultView;
    Page.Session.Ad d("DataViewOrig inal",dv);//put into the session the view
    this.DataGrid1. DataSource=dv;//assign the data source
    this.DataGrid1. DataBind();
    //In your sortCommand method
    if(Page.Session["DataViewOrigin al"]!=null) //if exists the dataview in the
    session
    {
    DataView dv=(DataView) Page.Session["DataViewOrigin al"]; //take the view
    dv.Sort=e.SortE xpression;//sort the view by the name of the column header
    clicked
    this.DataGrid1. DataSource=dv; //assign the source
    this.DataBind() ; //show the info
    }
    Hope this helps.
    Regards.
    josema.

    "Newbie" wrote:
    [color=blue]
    > Hello!
    >
    > I need help in making my datagrid sortable by clicking a column header.
    >
    > In the datagrid's property builder, Allow Sorting is checked. I am using a
    > Bound column and it's Sort Expression is set to the same value as the Data
    > Field value. But I dont know how to implement:
    >
    > private void dgResults_SortC ommand(object source,
    > System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
    > {
    >
    > }
    >
    > Please help.[/color]

    Comment

    Working...