GridView
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "False"
Font-Names = "Arial" OnRowDataBound = "OnRowDataBound">
<Columns>
<asp:BoundField DataField = "Item" HeaderText = "Item" />
<asp:BoundField DataField = "Price" HeaderText = "Price" />
</Columns>
</asp:GridView>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Price") });
dt.Rows.Add("Shirt", 200);
dt.Rows.Add("Football", 30);
dt.Rows.Add("Bat", 22.5);
dt.Rows.Add("Ring", 25);
dt.Rows.Add("Band", 77);
dt.Rows.Add("Glass", 57);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToDouble(e.Row.Cells[1].Text) > 50.0)
{
e.Row.Attributes["style"] = "background-color:red";
}
}
}
Output
Item | Price |
Shirt |
200 |
Football |
30 |
Bat |
22.5 |
Ring |
25 |
Band |
77 |
Glass |
57 |