Introduction:
In this article we will discuss about creating summaries in gridview,and also how to edit each and every row in gidview.
Main:
GridView is to show a set of records, you can also add some more interesting information, such as summary data.
In first step we need to set ShowFooter=”True”
<asp:GridView ID=”gridsample” runat=”server” DataSourceID=”sourceProducts”
AllowPaging=”True” OnDataBound=”gridSummary_DataBound” ShowFooter=”True” … >
See this below examble,i created one footer,and i calculated stock price values and
finally i summarised
protected void gridSummary_DataBound(object sender, EventArgs e)
{
decimal local_valueInStock = 0;
// The Rows collection includes only the rows that are displayed
// on the current page (not “virtual” rows).
foreach (GridViewRow row in gridsample.Rows)
{
decimal price = Decimal.Parse(row.Cells[2].Text);
int unitsInStock = Int32.Parse(row.Cells[3].Text);
valueInStock += price * unitsInStock;
}
// Update the footer.
GridViewRow footer = gridSummary.FooterRow;
// Set the first cell to span over the entire row.
footer.Cells[0].ColumnSpan = 3;
footer.Cells[0].HorizontalAlign = HorizontalAlign.Center;
// Remove the unneeded cells.Based on yours cell count,In my grid i have 3 columns
footer.Cells.RemoveAt(2);
footer.Cells.RemoveAt(1);
// Add the text.
footer.Cells[0].Text = “Total value in stock (on this page): ” +
local_valueInStock.ToString(“C”);
}
Conclusion:
Now,i hope you understood how to create a summarized footer,
Happy Coding.