Here is the example. You can implement this in RowDataBound Event of Gridview as follows:
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string name= textbox1.text;
SqlCommand cmd = new SqlCommand("select SUM(leave) from leave_rec where name=@empname",conn);
cmd.Parameters.Add(new SqlParameter("@empname", name));
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label leave_label = (Label)e.Row.FindControl("your label id");
object value = dr.GetValue(0);
leave_label.Text = value.ToString();
}
}
}
Here,we have label field(leave_label) as templatefiled in gridview.On
Gridview_RowDataBound
Event,we have calculated total leaves for particuler employee which will be displayed in label.