none
gridview 怎么在绑定好的数据之后添加一行数据在最后? RRS feed

  • 问题

  • gv.HeaderStyle.BackColor = System.Drawing.Color.FromName("#E2F0F9");
            GridViewRow gvrHead = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
            TableHeaderCell thcHeadLeft = new TableHeaderCell();
            thcHeadLeft.ColumnSpan = gv.Columns.Count - 1;
            thcHeadLeft.Text = "统计日期: " + startDate + "  至  " + overDate;
            thcHeadLeft.HorizontalAlign = HorizontalAlign.Left;
            gvrHead.Cells.Add(thcHeadLeft);
            TableHeaderCell thcHeadRight = new TableHeaderCell();
            thcHeadRight.ColumnSpan = 1;
            thcHeadRight.Text = "卡片单位:张";
            thcHeadRight.HorizontalAlign = HorizontalAlign.Right;
            gvrHead.Cells.Add(thcHeadRight);
            gv.Controls[0].Controls.AddAt(0, gvrHead);

    以上是头部添加一行数据

    求底部操作

    2015年7月14日 2:51

答案

  • 问题已经解决

    GridViewRow gvrFoot = new GridViewRow(gv.Rows.Count, gv.Rows.Count, DataControlRowType.Footer, DataControlRowState.Normal);

            //TableFooterRow tfr = new TableFooterRow();

            TableCell tcLeft = new TableCell();
            
            tcLeft.ColumnSpan = gv.Columns.Count - 1;
            tcLeft.Text = "制表日期: " + zbDate;
            tcLeft.HorizontalAlign = HorizontalAlign.Right;
            gvrFoot.Cells.Add(tcLeft);
            TableCell tcRight = new TableCell();
            tcRight.ColumnSpan = 1;
            tcRight.Text = "制表人: " + zbr;
            tcRight.HorizontalAlign = HorizontalAlign.Right;
            gvrFoot.Cells.Add(tcRight);
            
            gv.Controls[0].Controls.AddAt(gv.Rows.Count + 1, gvrFoot);

    • 已标记为答案 18k_HD 2015年7月14日 3:32
    2015年7月14日 3:29

全部回复

  • 问题已经解决

    GridViewRow gvrFoot = new GridViewRow(gv.Rows.Count, gv.Rows.Count, DataControlRowType.Footer, DataControlRowState.Normal);

            //TableFooterRow tfr = new TableFooterRow();

            TableCell tcLeft = new TableCell();
            
            tcLeft.ColumnSpan = gv.Columns.Count - 1;
            tcLeft.Text = "制表日期: " + zbDate;
            tcLeft.HorizontalAlign = HorizontalAlign.Right;
            gvrFoot.Cells.Add(tcLeft);
            TableCell tcRight = new TableCell();
            tcRight.ColumnSpan = 1;
            tcRight.Text = "制表人: " + zbr;
            tcRight.HorizontalAlign = HorizontalAlign.Right;
            gvrFoot.Cells.Add(tcRight);
            
            gv.Controls[0].Controls.AddAt(gv.Rows.Count + 1, gvrFoot);

    • 已标记为答案 18k_HD 2015年7月14日 3:32
    2015年7月14日 3:29
  • gv.Controls[0]  代表整个TABLE

    AddAt(gv.Rows.Count+1,gvrFoot);     必须+1

    2015年7月14日 3:31
  • @18k_HD

    感谢分享


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年7月15日 9:46
    版主