zoukankan      html  css  js  c++  java
  • SharePoin2010 的"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"];
    }
  • 相关阅读:
    UVALIVE 4819 最大流
    Directx 3D编程实例:随机绘制的立体图案旋转
    PHP漏洞全解(四)-xss跨站脚本攻击
    PHP漏洞全解(三)-客户端脚本植入
    PHP漏洞全解(二)-命令注入攻击
    PHP漏洞全解(一)-PHP网站的安全性问题
    BT5下安装Metasploit4.5方法
    Ubuntu使用apt-get安装本地deb包
    Linux按照时间查找文件
    Linux系统备份与还原
  • 原文地址:https://www.cnblogs.com/masahiro/p/10128988.html
Copyright © 2011-2022 走看看