Sorting Problem with Viewstate

Discussion in 'ASP .Net Datagrid Control' started by John Smith Jr., Jan 23, 2004.

  1. I did my first DataGrid with sorting. Problem I have is viewstate has to be
    on for it to work, even though i am passing a dataview and re-binding the
    datagrid with it as needed. This means the data is passed for the table,
    the viewstate for the page as ussual, then the viewstate var i am using to
    pass the dataview.

    Here is snipit of what i am doing, if someone could tell me if I am missing
    something, that would be great, although everything does work. I think I am
    sending way too much traffic than I need to.

    private void Page_Load(object sender, System.EventArgs e)

    {

    if (!IsPostBack)

    {

    sqlDataAdapter1.Fill(dataSet11);


    Session["dataView"] = dataSet11.Tables["Customers"].DefaultView;

    ViewState["Sort"] = string.Empty;

    ViewState["SortDirection"] = "ASC";

    DataGrid1.DataSource = Session["dataView"];

    DataGrid1.DataBind();

    }



    }



    private void DataGrid1_SortCommand(object source,
    System.Web.UI.WebControls.DataGridSortCommandEventArgs e)

    {

    string sortDirection = "ASC";

    DataView dv = (DataView) Session["dataView"];

    if (e.SortExpression == ViewState["Sort"].ToString() )

    {

    if (ViewState["SortDirection"].ToString() == "ASC")

    {

    sortDirection = "DESC";

    }

    else

    {

    sortDirection = "ASC";

    }

    }


    dv.Sort = e.SortExpression + " " + sortDirection;



    Session["dataView"] = dv;

    ViewState["SortDirection"] = sortDirection;

    ViewState["Sort"] = e.SortExpression;

    DataGrid1.DataSource = Session["dataView"];

    DataGrid1.DataBind();

    }
     
    John Smith Jr., Jan 23, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Rush
    Replies:
    2
    Views:
    583
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,698
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,402
    ujjc001
    Jul 27, 2005
  4. sck10
    Replies:
    6
    Views:
    965
    sck10
    Sep 1, 2006
  5. mark

    Viewstate errors... how do I get viewstate working?

    mark, Feb 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    300
Loading...

Share This Page