You must Sign In to post a response.
  • Category: ASP.NET

    Showing the data in footer is wrong in gridview using asp.net

    showing the data in footer is wrong in gridview using asp.net


    in a gridview in show the data in viewstate and i show the total in footer after click the row the amount is changed but the total is wrong

    my code

    protected void ddsales_SelectedIndexChanged(object sender, EventArgs e)
    {
    foreach (GridViewRow row in ddsales.Rows)
    {
    if (row.RowIndex == ddsales.SelectedIndex)
    {
    row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
    row.ToolTip = string.Empty;
    float bilamt = 0;
    double mr, wt, totlrp,mpr,totl;
    mr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    mpr = Convert.ToDouble((row.FindControl("lblmrp") as Label).Text);
    DataTable dtt1;
    dtt1 = (DataTable)ViewState["Products"];
    if (dtt1.Rows.Count != 0)
    {

    for (int i = 0; i < dtt1.Rows.Count; i++)
    {
    bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    // txtbillamountcash.Text = Convert.ToString(bilamt);

    bilamt += float.Parse(dtt1.Rows[i]["mrp"].ToString());
    if (txtqty.Text != "")
    {
    wt = double.Parse(txtqty.Text);
    totlrp = mr * wt;
    totl = mr + totlrp + bilamt;
    (row.FindControl("lblmrp") as Label).Text = Convert.ToString(totl);
    txtbillamountcash.Text = Convert.ToString(totl);
    }
    else
    {
    }
    }
    }
    }
    else
    {
    row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
    row.ToolTip = "Click to select this row.";
    }
    }
    }
  • #761414
    Hi Selvi,

    can you please tell more details about how you are binding the data. and how you are calculating the total.

    if it is datatable, once you changed the value you have to recalculate the total.

    Rayala HariKishore

    try..try..try...you achieved it.
    http://rayalaharikishore.wordpress.com/

  • #761425
    Hai Selvi,
    if you want to show the data in the footer of the GridView, don't do it as the way you are doing.
    Just use the RowDataBound control.
    In the SelectedIndexChanged Event handler, just filter the records and then simply bind the GridView. Nothing to do here.
    Now Create the RowdataBound event handler and there you can do the calculation for the Footer and display data in the footer,
    It will be more simpler and easy to handle. For displaying data in footer using the RowDataBound, you can use the below link:

    http://www.asp.net/web-forms/overview/data-access/custom-formatting/displaying-summary-information-in-the-gridview-s-footer-vb

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #761429
    Hello Selvi,

    You should have create a function for amount calculation so that you can recalculate the amount after binding the data whenever you are making changes you should call that function to recalculate the final amount.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761458
    Hi,

    If you search the samething in Google you may get no of links how to show the count in gridview footer, without tried out by your self how can you expect solution from others.?

    I request you to please tried out by your self, if you still face any critical issue then request for others help,

    I send you one of the link for the gridview footer count.

    http://www.dotnetspider.com/resources/45189-GridView-Footer-Count.aspx

    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761487
    i know mr. naveensanagasetti how to show the total on footer.i got the result .but my need is show the total in viewstate.in viewstate am getting wrongly thats y i post question in forums.

    mistake.bmp

    Delete Attachment

  • #761488
    Hi
    Can your share the code with Table script and sample data then we can solve fast. without table script we will create long time so.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761490
    Hello Kumar,

    She is already shared her code.

    She just have to create the function to calculate final total. So whenever she add the new item to the cart she just have to call the function only and the final amount will be calculated automatically.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761496

    You can calculate purpuse try this code


    double foottotal = 0;
    foreach (GridViewRow dr in GridView1.Rows)
    {
    double price = Convert.ToDouble(((Label)dr.FindControl("lblRPrice")).Text);
    int Qty = int.Parse(((TextBox)dr.FindControl("txtQty")).Text);
    double total = price * Qty;
    ((Label)dr.FindControl("lbltotal")).Text = Convert.ToString(total);
    foottotal = foottotal + total;
    }
    GridViewRow row = GridView1.FooterRow;
    ((Label)row.FindControl("lblfooterotal")).Text = Convert.ToString(foottotal);


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761498
    Hi selvi,

    Thanks for finding solution by your own, don't mistake me. If you try to get the solution by your own then only you became master in particular language, if you are looking for some one help in that case you can't able to learn anything.

    Without others help if you can't able to proceed to next level in that scenario you can expect others help, this is my advice, if you like you can follow other wise live it.

    All the best...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761501
    i tried it but i never got the output thats y i asked in forums mr. naveensanagasetti . still am doing but i never got it


    PLEASE REFER MY MISTAKE IMAGE I UPLOAD IT

    mistake.bmp

    Delete Attachment

  • #761508
    Hi selvi,

    As per your previous posts, you got problem in ViewState.? In that case better to put a break point in assign value to viewstate and get back the values from viewstate, and check the values are reflected properly or not.?

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761520
    Hi

    Just Place One method and call this method after data binding.


    private void Calc()
    {
    double foottotal = 0;
    foreach (GridViewRow dr in ddsales.Rows)
    {
    double price = Convert.ToDouble(((Label)dr.FindControl("lblmrp")).Text);
    //int Qty = int.Parse(((TextBox)dr.FindControl("txtQty")).Text);
    //double total = price * Qty;
    //((TextBox)dr.FindControl("lbltotal")).Text = Convert.ToString(total);
    foottotal = foottotal + price;
    }
    GridViewRow row = ddsales.FooterRow;
    ((Label)row.FindControl("Salary")).Text = Convert.ToString(foottotal);
    txtbillamountcash.Text = foottotal.ToString();
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761522
    Hi

    put this function globally and call this

    I have attached snapshots given below.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment


Sign In to post your comments