I have a label with long computed value and I want.to show that label value in grigldview footer textbox automatically, so that I can insert that same value in database.
I m new to this so please elaborate while giving answer.
I m using .aspx.cs
thanks in advance..
Loading
Abhishek KumarPosted May 29, 2014, 1:21 AM
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace gridViewTest
{
public partial class WebForm1 : System.Web.UI.Page
{
decimal total = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.populateData();
}
}
public void populateData()
{
DataTable dt = new DataTable();
dt.Columns.Add("CustomerID");
dt.Columns.Add("FirstName");
dt.Columns.Add("Amount");
dt.Rows.Add("0001", "Abhishek", 10000);
dt.Rows.Add("0002", "Ram", 20000);
dt.Rows.Add("0003", "Alice", 30000);
dt.Rows.Add("0004", "David", 40000);
Gridview1.DataSource = dt;
Gridview1.DataBind();
}
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label Amount = (Label)e.Row.FindControl("Label1");
decimal Presents = Convert.ToDecimal(Amount.Text);
total += Presents;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotal = (Label)e.Row.FindControl("lblTotal");
lblTotal.Text = total.ToString();
}
}
}
}
Hope this helps.