hi all
i have a problem that i don't know where to place the rowdatabound event and its not working in my code. i want to highlight that rows in grid whose price is greater than 50 but that's not working
[B]Default.aspx.cs[/B]
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label2.Text = "ghshajjjjjjjjjjjjjjjjjjjjjj";
// Get the price for this row.
int price = (int)DataBinder.Eval(e.Row.DataItem, "Sale_Price");
if (price > 20)
{
e.Row.BackColor = System.Drawing.Color.Blue;
e.Row.ForeColor = System.Drawing.Color.White;
e.Row.Font.Bold = true;
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
[B]Default.aspx[/B]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:GridView ID="grid" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
DataKeyNames="Ref#" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged3" OnRowDataBound="GridViewRowEventHandler">
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:BoundField DataField="Ref#" HeaderText="Ref#" ReadOnly="True"
SortExpression="Ref#" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="Purchase_Price" HeaderText="Purchase_Price"
SortExpression="Purchase_Price" />
<asp:BoundField DataField="Sale_Price" HeaderText="Sale_Price"
SortExpression="Sale_Price" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" />
<asp:BoundField DataField="Warning_Quantity" HeaderText="Warning_Quantity"
SortExpression="Warning_Quantity" />
<asp:BoundField DataField="Vendors" HeaderText="Vendors"
SortExpression="Vendors" />
<asp:BoundField DataField="Expiry_Month" HeaderText="Expiry_Month"
SortExpression="Expiry_Month" />
<asp:BoundField DataField="Expiry_Day" HeaderText="Expiry_Day"
SortExpression="Expiry_Day" />
<asp:BoundField DataField="Expiry_year" HeaderText="Expiry_year"
SortExpression="Expiry_year" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</p>
<p align="left" style="font-size: large">
<b>PRODUCT TABLE</b></p>
<p align="left" style="font-size: large">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>
</p>
<p align="left" style="font-size: large">
<asp:Label ID="Label2" runat="server" Text="Label321"></asp:Label>
</p>
<p align="left" style="font-size: large">
</p>
<p align="left" style="font-size: large">
</p>
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>