GridView插入自定义行

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" BorderWidth="1" Width="100%" BorderColor="Black" BorderStyle="Solid" CellPadding="0" Font-Size="12px" ForeColor="Black" PageIndex="0" AllowPaging=true PageSize="15" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCreated="GridView1_RowCreated">
   <Columns>
       <asp:BoundField HeaderText="全宗号" DataField="WholeID" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode=False >
           <ItemStyle HorizontalAlign="Center" />
       </asp:BoundField>
       <asp:BoundField HeaderText="目录号" DataField="MenuID" />
       <asp:BoundField HeaderText="全宗名称" DataField="WholeName" />
       <asp:BoundField HeaderText="类目名称" DataField="TypeName" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode=False />
       <asp:BoundField HeaderText="启止年代" DataField="BeginToEndDateTime" />
       <asp:BoundField HeaderText="保管期限" DataField="SaveTme" />
       <asp:BoundField HeaderText="案卷数(卷、件)" DataField="RecordsNumber" />
       <asp:BoundField HeaderText="盒数" DataField="BoxNumber" />
       <asp:BoundField HeaderText="存放地址" DataField="SetAddress" />
       <asp:BoundField HeaderText="利用形式" DataField="UsingStyle" />
       <asp:BoundField HeaderText="备注" DataField="Remark" />
   </Columns>
   <HeaderStyle BackColor="White" Font-Bold="False" Font-Size="12px" ForeColor="Black" Height="22px" />
   <RowStyle Height="22px" Font-Size="12px" HorizontalAlign="Center" />
   <AlternatingRowStyle Height="22px" BackColor="White" />
    <PagerStyle HorizontalAlign="Right" />
</asp:GridView>

/   

 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        DataControlRowType elemType = e.Row.RowType;
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            GridViewRow dgi2 = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
            Table tb = new Table();
            tb = (Table)GridView1.Controls[0];
            tb.Rows.AddAt(Convert.ToInt32(GridView1.Rows.Count) + 1, dgi2);
            TableCell tc11 = new TableCell();
            TableCell tc12 = new TableCell();
            TableCell tc13 = new TableCell();
            TableCell tc14 = new TableCell();
            TableCell tc15 = new TableCell();
            TableCell tc16 = new TableCell();
            TableCell tc17 = new TableCell();
            TableCell tc18 = new TableCell();
            TableCell tc19 = new TableCell();
            TableCell tc110 = new TableCell();
            TableCell tc111 = new TableCell();

            //计算合计
            decimal RecordsNumber, BoxNumber;
            RecordsNumber = 0; BoxNumber = 0;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                string temp1 = GridView1.Rows[i].Cells[6].Text.ToString();
                if (temp1 == "") temp1 = "0";
                RecordsNumber += Convert.ToDecimal(temp1);

                string temp2 = GridView1.Rows[i].Cells[7].Text.ToString();
                if (temp2 == "") temp2 = "0";
                BoxNumber += Convert.ToDecimal(temp2);
            }

            tc11.Text = "合计";
            tc11.Font.Bold = true;
            tc11.ForeColor = Color.Black;
            tc11.BackColor = Color.White;
            tc11.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc11);

            tc12.Text = "";
            tc12.ForeColor = Color.Black;
            tc12.BackColor = Color.White;
            tc12.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc12);

            tc13.Text = "";
            tc13.ForeColor = Color.Black;
            tc13.BackColor = Color.White;
            tc13.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc13);

            tc14.Text = "";
            tc14.ForeColor = Color.Black;
            tc14.BackColor = Color.White;
            tc14.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc14);

            tc15.Text = "";
            tc15.ForeColor = Color.Black;
            tc15.BackColor = Color.White;
            tc15.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc15);

            tc16.Text = "";
            tc16.ForeColor = Color.Black;
            tc16.BackColor = Color.White;
            tc16.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc16);

            tc17.ForeColor = Color.Black;
            tc17.BackColor = Color.White;
            tc17.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc17);
            tc17.Text = RecordsNumber.ToString();

            tc18.ForeColor = Color.Black;
            tc18.BackColor = Color.White;
            tc18.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc18);
            tc18.Text = BoxNumber.ToString();

            tc19.Text = "";
            tc19.ForeColor = Color.Black;
            tc19.BackColor = Color.White;
            tc19.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc19);

            tc110.Text = "";
            tc110.ForeColor = Color.Black;
            tc110.BackColor = Color.White;
            tc110.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc110);

            tc111.Text = "";
            tc111.ForeColor = Color.Black;
            tc111.BackColor = Color.White;
            tc111.HorizontalAlign = HorizontalAlign.Center;
            dgi2.Cells.Add(tc111);

            int nColumn = e.Row.Cells.Count;
            for (int i = 0; i < nColumn; i++)
            {
                e.Row.Cells.RemoveAt(0);
            }
        }
    } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值