Showing posts with label change GridView Row Background Color. Show all posts
Showing posts with label change GridView Row Background Color. Show all posts

Monday, 9 June 2014

How to Changing color of rows or a cell in gridview control of ASP.Net,change GridView Row Background Color ,Changing Gridview row color based on value in that row

Hai frnd this How to Changing color of rows or a cell in gridview control of ASP.Net

In  Head Section take the css color's and use it in RowDataBound
<head runat="server">
    <style type="text/css">
   
   
    .teal
    {
        background-color:Teal;
    }
    .green
    {
        background-color:Green;
    }
    </style>
    <title></title>

-------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

Aspx.cs Page

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


public partial class _Default : System.Web.UI.Page
{
    string cond = ConfigurationManager.ConnectionStrings["mydataconn"].ToString();
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter dap;
    DataSet ds;

    protected voidPage_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            grdview1.DataSource = myGridData();
            grdview1.DataBind();
        }

    }

    public DataSetmyGridData()
    {
        con = new SqlConnection(cond);
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "spdatadown";
        dap = new SqlDataAdapter(cmd);
        ds = new DataSet();
        dap.Fill(ds);
        return (ds);

       
    }
    protected voidgrdview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text.CompareTo("dora") == 0)
            {
                e.Row.CssClass = "green";
            }
            else
            {
                if (e.Row.Cells[1].Text.CompareTo("hello") == 0)
                {
                    e.Row.CssClass = "teal";
                }
            }
        }
    }
}