zoukankan      html  css  js  c++  java
  • [Asp.Net+C#]Datagrid使用技巧五(设置DataGrid的pager格式)

      /// <summary>
      /// 设置DataGrid的pager格式
      /// </summary>
      /// <param name="dgMain">需要处理的DataGrid</param>
      /// <param name="e">DataGride的ItemCreated事件参数</param>
      public static void DataGridPageSet(DataGrid dgMain, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
       if(e.Item.ItemType!=ListItemType.Pager)
       {
        return;
       }
       TableCell pager = (TableCell)(e.Item.Controls[0]);
       for (int i=0; i<pager.Controls.Count; i+=2)
       {
        Control o = pager.Controls[i];
        if (o is LinkButton)
        {//其他页
         LinkButton h = (LinkButton) o;
         h.Font.Underline=true;
        }
        else
        {
         //当前页
         Label l = (Label) o;
         l.ForeColor=Color.FromKnownColor(KnownColor.Red);
        }
       }
       StringBuilder strb=new StringBuilder("<table width=100%><tr><td width=50% align=left>");
       pager.Controls.AddAt(0,new LiteralControl(strb.ToString()));
       strb.Remove(0,strb.Length);
       int totalCount=0;
       if(dgMain.AllowCustomPaging==true)
       {
        totalCount=dgMain.VirtualItemCount;
       }
       else
       {
        if (dgMain.DataSource is DataTable)
        {
         totalCount=((DataTable)(dgMain.DataSource)).Rows.Count;
        }
        else if(dgMain.DataSource is DataView)
        {
         totalCount=((DataView)(dgMain.DataSource)).Table.Rows.Count;
        }
       }
       strb.AppendFormat("</td><td width=50% align=right>第<font color=red>{0}</font>页 共{1}页 共{2}条记录</td></tr></table>", dgMain.CurrentPageIndex+1 ,dgMain.PageCount,totalCount);
       pager.Controls.Add(new LiteralControl(strb.ToString()));
       return;
      }
  • 相关阅读:
    模块 hashlib模块
    设计模式
    类中双下方法
    工作小结 常见定制类
    python collections模块
    启动脚本
    anaconda镜像
    理解python的可变参数
    使用spark
    python 异常处理
  • 原文地址:https://www.cnblogs.com/JimZhang/p/226614.html
Copyright © 2011-2022 走看看