Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

foreach GridviewRow - skipping FooterRow

Posted on 2013-06-20
3
Medium Priority
?
766 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Assisted Solution

by:Sammy Ageil
Sammy Ageil earned 80 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 320 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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