HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

Rate It (17)

Last post 07-30-2007 2:56 AM by krishanmanral. 185 replies.

Sort Posts:

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-27-2007, 1:57 AM
    Locked

    i m having problem that when i select any header item for sorting i got the same result of sortdirection = acsending every time.

     

    ConvertSortDirectionToSql function alwawys returns "Asc" what should i do next

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-27-2007, 1:58 AM
    Locked

    i m having problem that when i select any header item for sorting i got the same result of sortdirection = acsending every time.

     

    ConvertSortDirectionToSql function alwawys returns "Asc" what should i do next

     

    my code is as below

     

    private string ConvertSortDir(SortDirection sortDireciton)

    {

    string newSortDirection = String.Empty;switch (sortDireciton)

    {

    case SortDirection.Ascending:

    newSortDirection = "ASC";

    break;

    case SortDirection.Descending:

    newSortDirection = "DESC";

    break;

    }

    return newSortDirection;

    }

    protected void grdvwdesignmaster_Sorting(object sender, GridViewSortEventArgs e)

    {

    DataTable objds1 = (DataTable)Session["desmas"];if (objds1 != null)

    {

    DataView dataView = new DataView(objds1);

    dataView.Sort = e.SortExpression + " " + ConvertSortDir(e.SortDirection);

    grdvwdesignmaster.DataSource = dataView;

    grdvwdesignmaster.DataBind();

    }

    }

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-27-2007, 3:00 AM
    Locked
    • Loading...
    • osmanmz
    • Joined on 07-25-2007, 8:01 AM
    • Posts 2

    Hi

    Store your sort direction in a viewStateVariable.

    Save the last direction once you're completed sorting.  I've used three states below:  ASC, DESC, unsorted:

     (In "grdvwdesignmaster_Sorting" change

    "dataView.Sort = e.SortExpression + " " + ConvertSortDir(e.SortDirection); "

    to:

    if (GridViewSortDirection.Length > 0)

    {

    dataView.Sort = e.SortExpression + " " + GridViewSortDirection;

    }

    ChangeSortDirection();

     

    ViewState property & function:

    private string GridViewSortDirection

    {

    get { return ViewState["SortDirection"] as string ?? "ASC"; }

    set { ViewState["SortDirection"] = value; }

    }

     

     private string ChangeSortDirection()

    {

    switch (GridViewSortDirection)

    {

    case "ASC":

    GridViewSortDirection = "DESC";

    break;

    case "DESC":

    GridViewSortDirection = "";

    break;

    default:

    GridViewSortDirection = "ASC";

    break;

    }

    return GridViewSortDirection;

    }

    }

    private string GridViewSortDirection

    {

    get { return ViewState["SortDirection"] as string ?? "ASC"; }

    set { ViewState["SortDirection"] = value; }

    }

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-27-2007, 12:30 PM
    Locked
    • Loading...
    • shakthi_001
    • Joined on 07-27-2007, 4:22 PM
    • Posts 1

     Hi Ryan thx for the post......i copied the code(GridView Sorting/Paging w/o a DataSourceControl DataSource)and it was working gr8.....but i moved the PopulatePublishersGridView() from page load to Button_Click.....Once i click the button i can see the Grid.....but if try clicking header text for sorting iam getting an message "NO DATA FOUND".....even if i click page number same error...but every thing was fine if it is in page_load......can plz tell me the problem...................thank you

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-30-2007, 2:40 AM
    Locked
    thanks it works for me
  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-30-2007, 2:56 AM
    Locked
    thank you very much it works for me
Page 13 of 13 (186 items) « First ... < Previous 9 10 11 12 13