如何计算网格视图中的页脚总数..... [英] how to calculate footer total in grid view.....

查看:85
本文介绍了如何计算网格视图中的页脚总数.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML code ...

HTML code...

<tr>
              <td>
                  Sr. No:-
              </td>
              <td>
                  <asp:TextBox ID="txtSrno" runat="server"  ></asp:TextBox>
                  <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"

                      ControlToValidate="txtSrno" Display="None" ErrorMessage="Enter SR No"

                      ValidationGroup="Validate"></asp:RequiredFieldValidator>
              </td>
          </tr>
          <tr>
              <td>
                  Iteam:-
              </td>
              <td>
                  <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                 <ContentTemplate>
                  <asp:DropDownList ID="ddlstItem" runat="server" AppendDataBoundItems="true">
                  </asp:DropDownList>
                  <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"

                      ControlToValidate="ddlstItem" Display="None" ErrorMessage="Select Any One Item"

                      InitialValue="0" ValidationGroup="Validate"></asp:RequiredFieldValidator>
                  </ContentTemplate>
                   </asp:UpdatePanel>
              </td>
          </tr>
          <tr>
              <td>
                  Qty:-
              </td>
              <td>
                  <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                  <ContentTemplate>
                          <asp:TextBox ID="txtQty" runat="server" onkeypress="return isNumberKey(event)" AutoPostBack="True"

                               ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"

                              ControlToValidate="txtQty" Display="None" ErrorMessage="Enter Qty"

                              ValidationGroup="Validate"></asp:RequiredFieldValidator>
                     </ContentTemplate>
              </asp:UpdatePanel>
              </td>
          </tr>
          <tr>
              <td>
                  Rate:-
              </td>
              <td>
                  <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                  <ContentTemplate>
                          <asp:TextBox ID="txtRate" runat="server" onkeypress="return isNumberKey(event)"

                               ontextchanged="txtRate_TextChanged" AutoPostBack="True" ></asp:TextBox>
                          <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"

                              ControlToValidate="txtRate" Display="None" ErrorMessage="Enter Rate"

                              ValidationGroup="Validate"></asp:RequiredFieldValidator>
                   </ContentTemplate>
                   </asp:UpdatePanel>
              </td>
          </tr>
          <tr>
              <td>
                  Amount:-
              </td>
              <td>
                  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                      <ContentTemplate>
                          <asp:TextBox ID="txtAmount" runat="server"  Enabled="false"  EnableTheming="True"></asp:TextBox>
                      </ContentTemplate>
                  </asp:UpdatePanel>
              </td>
          </tr>
          <tr>
              <td>

              </td>
              <td>
                  <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click"

                      ValidationGroup="Validate" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
              </td>
          </tr>
          <tr>
              <td>

                  &nbsp;</td>
              <td>
                  <asp:ValidationSummary ID="ValidationSummary1" runat="server"

                      ShowMessageBox="True" ShowSummary="False" ValidationGroup="Validate"

                      BorderColor="#003300" />
              </td>
          </tr>
      </table>

  </div>
  <asp:GridView ID="GridView1" runat="server" BorderColor="Black" ShowFooter="true"

      BorderStyle="Solid" BorderWidth="1px" ForeColor="#333300"

      >
      <RowStyle BorderWidth="1px" />
  </asp:GridView>







cs code...






cs code...

public partial class Default2 : System.Web.UI.Page
{
    general gen=new general();

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dtMax = gen.GetDataTable("SPSelectDCNMForMaxRecord");

        if (dtMax != null && dtMax.Rows.Count > 0 && dtMax.Rows[0]["maxRecord"] != null)
            {

                string strMaxNo = (Convert.ToInt32(dtMax.Rows[0]["maxRecord"].ToString()) + 1).ToString();

                lblDCNO.Text = strMaxNo.PadLeft(10, '0');
                fillCustomerName();
                
            }
             else
        {
            lblDCNO.Text = "0000000001";
        }
        fillItem();
        txtDate.Text = DateTime.Today.Date.ToString("dd/MM/yyyy");
 }
 
    #region "Fill Dropdown For Customer Name"
    private void fillCustomerName()
    {
        DataTable dtCustomer = gen.GetDataTable("SPSelectCUST");
        ddlstName.DataTextField = "Name";
        ddlstName.DataValueField = "CUST_CD";
        ddlstName.DataSource = dtCustomer;
        ddlstName.DataBind();
    }
    #endregion
    #region "Fill Dropdown For Item"
    private void fillItem()    
    {
        DataTable dtItem = gen.GetDataTable("SPselectITEM");
        ddlstItem.DataTextField = "ST_DESC";
        ddlstItem.DataValueField = "ST_CD";
        ddlstItem.DataSource = dtItem;
        ddlstItem.DataBind();
        
    }
    #endregion
    #region "Bind Gridview"
    private void Bindgrid(int rowcount)
    {
        DataTable dt = new DataTable();
        DataRow dr;
        dt.Columns.Add(new System.Data.DataColumn("SR NO", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Item",typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Qty", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Rate", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Amount", typeof(String)));

        if (ViewState["CurrentData"] != null)
        {
            for (int i = 0; i < rowcount + 1; i++)
            {
                dt = (DataTable)ViewState["CurrentData"];
                if (dt.Rows.Count > 0)
                {
                    dr = dt.NewRow();
                    dr[0] = dt.Rows[0][0].ToString();
                }
            }
            dr = dt.NewRow();
            dr[0] = txtSrno.Text;
            dr[1] = ddlstItem.SelectedItem.Text.ToString();
            dr[2] = txtQty.Text;
            dr[3] = txtRate.Text;
            dr[4] = txtAmount.Text;
            dt.Rows.Add(dr);
        }
        else
        {
            dr = dt.NewRow();
            dr[0] = txtSrno.Text;
            dr[1] = ddlstItem.SelectedItem.Text.ToString();
            dr[2] = txtQty.Text;
            dr[3] = txtRate.Text;
            dr[4] = txtAmount.Text;
            dt.Rows.Add(dr);  
        }
        if (ViewState["CurrentData"] != null)
        {
            GridView1.DataSource = (DataTable)ViewState["CurrentData"];
            GridView1.DataBind();
        }
        else
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        ViewState["CurrentData"] = dt;

    }
    #endregion
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (ViewState["CurrentData"] != null)
        {
            DataTable dt = (DataTable)ViewState["CurrentData"];
            int count = dt.Rows.Count;
            Bindgrid(count);
        }
        else
        {
            Bindgrid(1);
        }

推荐答案

declare totalCountApp variable at top:



protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)

{

try

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

totalCountApp += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, \"Count\"));

}

if (e.Row.RowType == DataControlRowType.Footer)

{

e.Row.Cells[e.Row.Cells.Count - 1].Text = totalCountApp.ToString();

e.Row.Cells[0].Text = \"Page\" + (gvReport.PageIndex + 1) + \"of\" + (gvReport.PageCount);



}



}

catch (Exception ex)

{

MessageBox.Show(ex.Message.ToString());

}



}
declare totalCountApp variable at top:

protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
totalCountApp += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Count"));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[e.Row.Cells.Count - 1].Text = totalCountApp.ToString();
e.Row.Cells[0].Text = "Page" + (gvReport.PageIndex + 1) + "of" + (gvReport.PageCount);

}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}

}


Here’s one way to do it: http://forums.asp.net/t/1119102.aspx[^]
Here's one way to do it: http://forums.asp.net/t/1119102.aspx[^]


Here you get full code for adding total at footer:

http://stackoverflow.com/questions/11734308/displaying-total-in-footer-of-gridview-and-also-add-sum-of-columnsrow-vise-in[^]



Here example with demo Project:

SQL Pager Control for Grid View, DataList, Repeater, DataGridView[^]



If this one help to you pls accept as answer and vote.
Here you get full code for adding total at footer:
http://stackoverflow.com/questions/11734308/displaying-total-in-footer-of-gridview-and-also-add-sum-of-columnsrow-vise-in[^]

Here example with demo Project:
SQL Pager Control for GridView, DataList, Repeater, DataGridView[^]

If this one help to you pls accept as answer and vote.


这篇关于如何计算网格视图中的页脚总数.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆