I want to display the values from column named “total” on a label in my
GridView footer.
The value of “total” column is same along every row so it does not matter which ever cell is chosen as long as we are in that column.
I am using a template-field for my column “total” and I am hiding it by making its visibility=false. so what i want is i want to display the value from my column named total on to a label which is inside my gridview
Here is the code sample I have tried, but its giving an error:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int total;
if (e.Row.RowType == DataControlRowType.DataRow)
{
total = Convert.ToInt32(((DataRowView)e.Row.DataItem)["total"].ToString());
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblamount7 = (Label)e.Row.FindControl("Label27");
lblamount7.Text =total.ToString(); // use of unassigned local variable 'total'
}
}
this is the aspx of the hidden column
‘> ‘>
For hiding the column take a Hiddeneeild in the Template-Field of GridView. The syntax will be like
Now to calculate total and show it in footer of GridView you can do like
It will surely work. Good Luck and do comment if it worked.