'basic calculation
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("OASGN")+Eval("WASGN")+Eval("EASGN") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
'more advanced should be sent to a backend function
<asp:TemplateField HeaderText="Percent">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# findpercent((Eval("OASGN")+Eval("WASGN")+ Eval("EASGN")) , Eval("TAUTH")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
'backend function
Public Function FindPercent(ByVal total As Double, ByVal auth As Double)
Dim percent As Double = total / auth
Dim spercent As String = percent.ToString("P")
Return (spercent)
End Function
Sub gv_RowDatabound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "price")) < 10.0 Then
e.Row.BackColor = Drawing.Color.Yellow
e.Row.ForeColor = Drawing.Color.Black
End If
End If
End Sub
<asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label>
Public Function Dividestuff(ByVal number1 As Double, ByVal number2 As Double)
Dim answer As Double = number1 / number2
Return (answer)
End Function
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControls.DataControlField'. 'asp:Label' is of type 'System.Web.UI.WebControls.Label'.
Source Error:
Line 60: DataFormatString="{0:c}" HeaderText="Dec 07" HtmlEncode="False"
Line 61: SortExpression="Dec 07" />
Line 62: <asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label>
Line 63: <asp:BoundField ApplyFormatInEditMode="True" DataField="Jan" DataFormatString="{0:c}"
Line 64: HeaderText="Jan" ReadOnly="True" SortExpression="Jan">
<asp:TemplateField HeaderText="Percent">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label> </ItemTemplate>
</asp:TemplateField>
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30057: Too many arguments to 'Public Function Dividestuff(number1 As Double, number2 As Double) As Object'.
Source Error:
Line 62: <asp:TemplateField HeaderText="Percent">
Line 63: <ItemTemplate>
Line 64: <asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label> </ItemTemplate>
Line 65: </asp:TemplateField>
Line 66: <asp:BoundField ApplyFormatInEditMode="True" DataField="Jan" DataFormatString="{0:c}"
Source File: D:\Repcom\template\Reports\CustomerSalesForYearByMonthWithREPID.aspx Line: 64
Hit this link ,where it has shoen how you can change cell's back color as per condition
http://www.codeproject.com/KB/webforms/gridcolumnformatting.aspx
Thanks
Harshad