Permalink
Browse files

2006-10-12 Igor Zelmanovich <igorz@mainsoft.com>

	* GridView.cs: fixed: EnableSortingAndPagingCallbacks feature.
	when postback is invoked after callback control state is restored
	properly. 


svn path=/trunk/mcs/; revision=66613
  • Loading branch information...
1 parent f1e7967 commit 901f16172bdc8485ef2d7ee60389bc013d0175a8 Igor Zelmanovich committed Oct 12, 2006
@@ -1,5 +1,11 @@
2006-10-12 Igor Zelmanovich <igorz@mainsoft.com>
+ * GridView.cs: fixed: EnableSortingAndPagingCallbacks feature.
+ when postback is invoked after callback control state is restored
+ properly.
+
+2006-10-12 Igor Zelmanovich <igorz@mainsoft.com>
+
* GridView.cs: fixed: Sorting feature.
When sorting EditIndex and PageIndex are reseted
@@ -98,11 +98,11 @@ public class GridView: CompositeDataBoundControl, ICallbackEventHandler, ICallba
// Control state
int pageIndex;
- int pageCount = 0;
+ int pageCount;
int selectedIndex = -1;
int editIndex = -1;
SortDirection sortDirection = SortDirection.Ascending;
- string sortExpression = string.Empty;
+ string sortExpression;
public GridView ()
{
@@ -535,6 +535,8 @@ public virtual string[] DataKeyNames
return editIndex;
}
set {
+ if (value == editIndex)
+ return;
editIndex = value;
RequireBinding ();
}
@@ -728,6 +730,8 @@ public virtual string[] DataKeyNames
return pageIndex;
}
set {
+ if (value == pageIndex)
+ return;
pageIndex = value;
RequireBinding ();
}
@@ -930,12 +934,28 @@ public virtual string[] DataKeyNames
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public virtual SortDirection SortDirection {
get { return sortDirection; }
+ private set {
+ if (sortDirection == value)
+ return;
+ sortDirection = value;
+ RequireBinding ();
+ }
}
[BrowsableAttribute (false)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public virtual string SortExpression {
- get { return sortExpression; }
+ get {
+ if (sortExpression == null)
+ return String.Empty;
+ return sortExpression;
+ }
+ private set {
+ if (sortExpression == value)
+ return;
+ sortExpression = value;
+ RequireBinding ();
+ }
}
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
@@ -1573,9 +1593,8 @@ public virtual void Sort (string newSortExpression, SortDirection newSortDirecti
if (IsBoundUsingDataSourceID) {
EditIndex = -1;
PageIndex = 0;
- sortExpression = args.SortExpression;
- sortDirection = args.SortDirection;
- RequireBinding ();
+ SortExpression = args.SortExpression;
+ SortDirection = args.SortDirection;
}
OnSorted (EventArgs.Empty);
@@ -1708,6 +1727,12 @@ protected internal override void LoadControlState (object ob)
protected internal override object SaveControlState ()
{
+ if (EnableSortingAndPagingCallbacks) {
+ Page.ClientScript.RegisterHiddenField (ClientID + "_Page", PageIndex.ToString ());
+ Page.ClientScript.RegisterHiddenField (ClientID + "_SortExpression", SortExpression);
+ Page.ClientScript.RegisterHiddenField (ClientID + "_SortDirection", ((int)SortDirection).ToString());
+ }
+
object bstate = base.SaveControlState ();
return new object[] {
bstate, pageIndex, pageCount, selectedIndex, editIndex, sortExpression, sortDirection, DataKeyNames
@@ -1811,24 +1836,15 @@ void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
RaiseCallbackEvent (eventArgs);
}
- string callbackResult;
protected virtual void RaiseCallbackEvent (string eventArgs)
{
string[] clientData = eventArgs.Split ('|');
- pageIndex = int.Parse (clientData[0]);
- sortExpression = HttpUtility.UrlDecode (clientData[1]);
- if (sortExpression == "") sortExpression = null;
- RequireBinding ();
+ PageIndex = int.Parse (clientData[0]);
+ SortExpression = HttpUtility.UrlDecode (clientData [1]);
+ SortDirection = (SortDirection) int.Parse (clientData [2]);
- RaisePostBackEvent (clientData[2]);
- EnsureDataBound ();
-
- StringWriter sw = new StringWriter ();
- sw.Write (PageIndex.ToString() + '|' + SortExpression + '|');
-
- HtmlTextWriter writer = new HtmlTextWriter (sw);
- RenderGrid (writer);
- callbackResult = sw.ToString ();
+ RaisePostBackEvent (clientData[3]);
+ DataBind ();
}
string ICallbackEventHandler.GetCallbackResult ()
@@ -1838,7 +1854,14 @@ string ICallbackEventHandler.GetCallbackResult ()
protected virtual string GetCallbackResult ()
{
- return callbackResult;
+ PrepareControlHierarchy ();
+
+ StringWriter sw = new StringWriter ();
+ sw.Write (PageIndex.ToString () + '|' + SortExpression + '|' + (int) SortDirection + '|');
+
+ HtmlTextWriter writer = new HtmlTextWriter (sw);
+ RenderGrid (writer);
+ return sw.ToString ();
}
string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
@@ -1854,10 +1877,19 @@ protected virtual string GetCallbackScript (IButtonControl control, string argum
return null;
}
- [MonoTODO]
protected override void OnPagePreLoad (object sender, EventArgs e)
{
base.OnPagePreLoad (sender, e);
+
+ if (Page.IsPostBack && EnableSortingAndPagingCallbacks) {
+ int page;
+ if (int.TryParse (Page.Request.Form [ClientID + "_Page"], out page))
+ PageIndex = page;
+ int dir;
+ if (int.TryParse (Page.Request.Form [ClientID + "_SortDirection"], out dir))
+ SortDirection = (SortDirection) dir;
+ SortExpression = Page.Request.Form [ClientID + "_SortExpression"];
+ }
}
protected internal override void OnPreRender (EventArgs e)
@@ -1875,6 +1907,7 @@ protected internal override void OnPreRender (EventArgs e)
string script = string.Format ("var {0} = new Object ();\n", cgrid);
script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
script += string.Format ("{0}.sortExp = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (SortExpression == null ? "" : SortExpression));
+ script += string.Format ("{0}.sortDir = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral ((int) SortDirection));
script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
@@ -1,7 +1,7 @@
function GridView_ClientEvent (ctrlId, evnt)
{
var gridData = eval (ctrlId + "_data");
- var clientData = gridData.pageIndex + '|' + escape (gridData.sortExp) + '|' + evnt;
+ var clientData = gridData.pageIndex + '|' + escape (gridData.sortExp) + '|' + gridData.sortDir + '|' + evnt;
WebForm_DoCallback (gridData.uid, clientData, GridView_ClientRender, ctrlId, GridView_ClientRender_Error);
}
@@ -11,9 +11,18 @@ function GridView_ClientRender (data, ctx)
var grid = document.getElementById (ctx);
var i = data.indexOf ("|");
var j = data.indexOf ("|", i+1);
+ var k = data.indexOf ("|", j+1);
gridData.pageIndex = parseInt (data.substring (0, i));
gridData.sortExp = unescape (data.substring (i+1, j));
- grid.innerHTML = data.substr (j+1);
+ gridData.sortDir = parseInt (data.substring (j+1, k));
+ grid.innerHTML = data.substr (k+1);
+
+ var page = document.getElementById(ctx + "_Page");
+ page.value = gridData.pageIndex;
+ var sortExp = document.getElementById(ctx + "_SortExpression");
+ sortExp.value = gridData.sortExp;
+ var sortDir = document.getElementById(ctx + "_SortDirection");
+ sortDir.value = gridData.sortDir;
}
function GridView_ClientRender_Error (data, ctx)

0 comments on commit 901f161

Please sign in to comment.