zoukankan      html  css  js  c++  java
  • GridView专题

    1.

    <asp:TemplateField HeaderText="总额">
              <ItemTemplate>
              <asp:Label ID="lblqty" runat="server"  Text='<%#Bind("QTY") %>'>'></asp:Label>//绑定数据源字段
              </ItemTemplate>
              </asp:TemplateField>
    

    2.合并某一列相同的行

     ///  <summary>   
        ///   合并GridView列中相同的行   
        ///   </summary>   
        ///   <param   name="GridView1">GridView对象</param>   
        ///   <param   name="cellNum">需要合并的列</param>   
        public static void GroupRows(GridView GridView1, int cellNum)
        {
            int i = 0, rowSpanNum = 1;
            while (i < GridView1.Rows.Count - 1)
            {
                GridViewRow gvr = GridView1.Rows[i];
                for (++i; i < GridView1.Rows.Count; i++)
                {
                    GridViewRow gvrNext = GridView1.Rows[i];
                    if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
                    {
                        gvrNext.Cells[cellNum].Visible = false;
                        rowSpanNum++;
                    }
                    else
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        rowSpanNum = 1;
                        break;
                    }
                    if (i == GridView1.Rows.Count - 1)
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                    }
                }
            }
        }

    2.2根据某一列合并相同的行 同时合并其他指定列

     ///  <summary>   
        ///   合并GridView列中相同的行
        ///  根据GridView某特定相同的行 同时可以合并其他列 
        ///   </summary>   
        ///   <param   name="GridView1">GridView对象</param>   
        ///   <param   name="cellNum">需要合并的列</param>   
        public static void GroupRows(GridView GridView1, int cellNum)
        {
            int i = 0, rowSpanNum = 1;
            while (i < GridView1.Rows.Count - 1)
            {
                GridViewRow gvr = GridView1.Rows[i];//上一行
                for (++i; i < GridView1.Rows.Count; i++)
                {
                    GridViewRow gvrNext = GridView1.Rows[i];//下一行
                    if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)//判断合并的条件
                    {
                        gvrNext.Cells[cellNum].Visible = false;
                        gvrNext.Cells[cellNum + 1].Visible = false;
                        gvrNext.Cells[cellNum + 4].Visible = false;
                        rowSpanNum++;
                    }
                    else
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        gvr.Cells[cellNum + 1].RowSpan = rowSpanNum;
                        gvr.Cells[cellNum + 4].RowSpan = rowSpanNum;
                        rowSpanNum = 1;
                        break;
                    }
                    if (i == GridView1.Rows.Count - 1)
                    {
                        gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        gvr.Cells[cellNum + 1].RowSpan = rowSpanNum;
                        gvr.Cells[cellNum + 4].RowSpan = rowSpanNum;
                    }
                }
            }
        }

      

  • 相关阅读:
    IoC~MVC3+EF+Autofac实现松耦合的系统架构
    IoC~高效的Autofac
    Autofac 依赖注入框架 使用
    C# socket编程实践——支持广播的简单socket服务器
    简单理解Socket
    利用html 5 websocket做个山寨版web聊天室(手写C#服务器)
    c# 实现WebSocket
    oracle中clob字段的使用
    查找程序加载的动态库的路径
    wordpress在window下完美实现301重定向的方法
  • 原文地址:https://www.cnblogs.com/jonson1126/p/3075655.html
Copyright © 2011-2022 走看看