Changing the color of row of the GridView on the basis of particular cell value in ASP.NET C#.

Step 1

(Add the following code to your  Default.aspx page)

<div>

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" onrowdatabound="GridView1_RowDataBound"
                    AutoGenerateColumns="False" CellPadding="4">
                    <RowStyle BackColor="Beige" ForeColor="#333333" HorizontalAlign="Center" Font-Bold="true"/>

                    <Columns>

                        <asp:BoundField DataField="TYPE" HeaderText="Type" />
                        <asp:BoundField DataField="CHANNEL" HeaderText="Chanel" />
                        <asp:BoundField DataField="CALLERID" HeaderText="Caller ID" />

                        <asp:BoundField DataField="RINGING_TIME" HeaderText="RingDuration" />
                        <asp:BoundField DataField="DURATION" HeaderText="CallDuration" />
                    </Columns>

                </asp:GridView></div>

Step 2

On the RowDataBound event of the GridView write the following code

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[0].Text == "INCOMING")
            {
                e.Row.Font.Bold = false
                e.Row.BackColor = System.Drawing.Color.Red;

            }

        }
}

Ebook Download
View all
Learn
View all