SharePoint 2007/2010 的SPGridView 控件常见的两个问题
問題一:無法顯示分頁的頁碼。
很多朋友很奇怪明明已經設置如下的代碼
oGrid.AllowPaging = true;
oGrid.PageSize = 2;
oGrid.PageIndexChanging +=new GridViewPageEventHandler(oGrid_PageIndexChanging);
但是頁面上無法顯示頁碼。
這個是SharePoint 自己的問題,我們需要加入下面一行代碼
Controls.Add(oGrid);
oGrid.PagerTemplate = null;//這行就是要加的代碼,順序很重要,一定要在Controls.Add之后,DataBind();之前
oGrid.DataBind();
?
現在再試試,是不是就可以看見頁碼了^_^
?
?
問題二:啟用了過濾后,在翻頁以后,發現在選擇下一頁,SPGridView會加載所有的數據,而不是filter過濾的數據。過濾功能失效了。
?
因為在render 下一頁后,無法繼續保存filter .所以這里有這樣一個辦法大家可以試試:
首先在OnPreRender里插入下面代碼保存FilterExpression 到ViewState中,(記得確保代碼里Enable ViewState)
protected override void OnPreRender(EventArgs e) {
ViewState["FilterExpression"] = odsDataSource.FilterExpression;
base.OnPreRender(e);
}
然后
在您的Controls.Add(odsDataSource); 之前插入下面的代碼,
HttpRequest req = HttpContext.Current.Request; if (req.Form["__CALLBACKID"] == null ||
req.Form["__CALLBACKPARAM"] == null ||
!req.Form["__CALLBACKID"].EndsWith("ExampleGrid"))
{
if (ViewState["FilterExpression"] != null)
odsDataSource.FilterExpression = (string)ViewState["FilterExpression"];
}
轉載于:https://www.cnblogs.com/KingStar/archive/2010/12/17/1909030.html
總結
以上是生活随笔為你收集整理的SharePoint 2007/2010 的SPGridView 控件常见的两个问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: flash player10.1 + F
- 下一篇: 使用socket的Linux上的C语言文