Learn to build secure applications from the mindset of the hacker and avoid being exploited.
<asp:GridView ID="my_GridView" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" onrowdatabound="my_GridView_RowDataBound">
<Columns>
<asp:BoundField DataField="my_date" HeaderText="Date" ReadOnly="True" SortExpression="date" />
<%-- <asp:BoundField DataField="my_rate" HeaderText="Rate" ReadOnly="True" SortExpression="my_rate"/> --%>
<asp:BoundField DataField="my_rate" HeaderText="Rate" ReadOnly="True" SortExpression="my_rate" DataFormatString="{0:p}"/>
</Columns>
</asp:GridView>
protected void my_GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
float cellvalue;
bool b = float.TryParse(e.Row.Cells[1].Text, out cellvalue);
if (b)
b = float.TryParse(e.Row.Cells[1].Text, out cellvalue);
{
if (cellvalue >= 0.90)
{
e.Row.Cells[1].BackColor = System.Drawing.ColorTranslator.FromHtml("#33FF00"); //Green
}
if ((cellvalue < 0.90) && (cellvalue >= 0.80))
{
e.Row.Cells[1].BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFF00"); //Yellow
}
if (cellvalue < 0.80)
{
e.Row.Cells[1].BackColor = System.Drawing.ColorTranslator.FromHtml("#FF0000"); //Red
}
//double value = double.Parse(cellvalue.Replace(" %", string.Empty)) / 100;
//double value=double.Parse(cellvalue.Replace("%","").Trim()))/100;
/*
if (cellvalue == 0)
{
e.Row.Cells[1].BackColor = System.Drawing.ColorTranslator.FromHtml("#FF0000"); //Red
}
*/
/*
double.Parse(str.Replace(" %", string.Empty)) / 100
double value=double.Parse(percentString.Replace("%","").Trim()))/100;
*/
}
}
}
Do more with
Premium Content
You need an Expert Office subscription to comment.Start Free Trial