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


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)



<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <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" />
                <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" />
            <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" />
    <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 align="left" style="font-size: large">
        <asp:Label ID="Label2" runat="server" Text="Label321"></asp:Label>
    <p align="left" style="font-size: large">
    <p align="left" style="font-size: large">
    &nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label1" runat="server"></asp:Label>

Recommended Answers

Is the rowDataBound event getting called at all? It looks right to me. Or is it some code inside the event that isn't working as it should?

Jump to Post

All 2 Replies

Is the rowDataBound event getting called at all? It looks right to me. Or is it some code inside the event that isn't working as it should?

As its not running in an AJAX panel from what I can see, would the page also need a postback to apply the colour change? Admittedly I lack experience within ASP.Net but that would be my first idea :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.