Solved

foreach GridviewRow - skipping FooterRow

Posted on 2013-06-20
3
713 Views
Last Modified: 2013-06-26
Hi

Im trying to loop through my gridview to update datarows and insert data in the footer row.
For my test I've 4 datarows to update
1 footerrows to insert
In the code below it seems to only loop through the datarows ie it goes through the loop 4 times and skips the Footer row..

 foreach (GridViewRow Row in GridView1.Rows)
       
           
        {
         
           if (Row.RowType == DataControlRowType.DataRow) // normal editable row
           {
          // update
          }
     else if (Row.RowType == DataControlRowType.Footer)
           {
          // insert
           }
   }


Any ideas?
0
Comment
Question by:louise_8
3 Comments
 
LVL 27

Assisted Solution

by:Sammy
Sammy earned 20 total points
ID: 39265628
You need to use the code in the RowDataBind event

//Something like this
void detailsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // add the UnitPrice and QuantityTotal to the running total variables
        priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, _
          "UnitPrice"));
        quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, _
          "Quantity"));
    }
    else if (e.Row.RowType == DataControlRowType.Footer)
    {
        e.Row.Cells[0].Text = "Totals:";
        // for the Footer, display the running totals
        e.Row.Cells[1].Text = priceTotal.ToString("c");
        e.Row.Cells[2].Text = quantityTotal.ToString("d");
       
        e.Row.Cells[1].HorizontalAlign = _
          e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
        e.Row.Font.Bold = true;
    }
}
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 80 total points
ID: 39266508
GridView.Rows only returns the DataRows and not the Footer.
You get explicit access to footer via GridView.FooterRow property.

Check this: http://geekswithblogs.net/casualjim/archive/2005/08/29/51360.aspx
0
 

Author Closing Comment

by:louise_8
ID: 39280044
thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now