Asp.net how to create calculated column with gridview boundfield

"vb.net"
Private iTotal As Integer = 0
Protected Sub GridView_RowDataBound(sender As Object, e As GridViewRowEventArgs)
Try
' chek grid view rowtype is datarow
If e.Row.RowType = DataControlRowType.DataRow Then

iTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Your Col Name"))
End If


'chek grid view rowtype is Footer
If e.Row.RowType = DataControlRowType.Footer Then
' Add footer row values.
e.Row.Cells(0).Text = "Total"
e.Row.Cells(0).Font.Bold = True
e.Row.Cells(1).Text = iTotal.ToString()

End If
Catch ex As Exception
Throw ex
End Try
End Sub

"c#"
int iTotal=0;
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
// chek grid view rowtype is datarow
if (e.Row.RowType == DataControlRowType.DataRow)
{
iTotal+= Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Your Col Name"));


}

//chek grid view rowtype is Footer
if (e.Row.RowType == DataControlRowType.Footer)
{
// Add footer row values.
e.Row.Cells[0].Text = "Total";
e.Row.Cells[0].Font.Bold = true;
e.Row.Cells[1].Text = iTotal.ToString();
}

}
catch (Exception ex)
{
throw ex;
}
}

Walang komento:

Mag-post ng isang Komento