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
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Christofel HakimPosted May 24, 2010, 3:23 AM
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.