On page load row calculation in grid view
i want to calculate some calculation in grid view template field on page load please help me
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Christofel Hakim81 reputationPosted May 23, 2010, 11:23 PM EDT
You can do this by adding some function on your page load.
here an example:
protected void Page_Load(arguments)
{
if(!Page.IsPostBack)
{
BindGridView(); //a methods to bind your gridview with the datasource
}
}
protected void BindGridView()
{
myGridView.DataSource = myDataSource;
myGridView.DataBind();
}
then add an event 'OnRowDataBound' to your GridView.
the event method would be like this:
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Then do your calculation of the item template here
}
}
so, every time when you load the page, you bind the gridview to the datasource, then when the data for each row is bound, it will do your calculation.