Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Sorting Problem with Viewstate

Reply
Thread Tools

Sorting Problem with Viewstate

 
 
John Smith Jr.
Guest
Posts: n/a
 
      01-23-2004
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.DataGridSortCommandEvent Args 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();

}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ViewState: "function 'ViewState.get_Item' evaluated and returned null" Steph ASP .Net 2 05-11-2011 02:35 PM
Errors: Failed to load viewstate. & Validation of viewstate MAC failed. sck10 ASP .Net 6 09-01-2006 05:59 PM
Loading usercontrols, viewstate problem, slighly different from all others "viewstate uc problems" please help... ujjc001 ASP .Net 0 07-27-2005 01:52 PM
Viewstate errors... how do I get viewstate working? mark ASP .Net Building Controls 0 02-20-2004 02:17 PM
Corrupted ViewState (Yes, another issue concerning viewstate) Ben Rush ASP .Net 2 12-05-2003 04:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57