This is a migrated thread and some comments may be shown as answers.

Change RadGrid cell color based on flag

4 Answers 1955 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 16 Sep 2011, 04:22 PM
HI Guys,

How do I go about changing a RadGrid cell color based on a database flag?

William

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2011, 08:17 PM
Hello,

protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
{
     //Is it a GridDataItem
     if (e.Item is GridDataItem)
     {
           //Get the instance of the right type
           GridDataItem dataBoundItem = e.Item as GridDataItem;
//if(dataBoundItem.GetDataKeyValue("ID").ToString() == "you Compared Text") // you can also use datakey also
                      if ( dataBoundItem[ "ColumnUniqueName"].Text == "you Compared Text" )
           {
                 dataBoundItem[ "ColumnUniqueName"].ForeColor = Color.Red; // chanmge particuler cell
                e.Item.BackColor = System.Drawing.Color.LightGoldenrodYellow; // for whole row
//dataItem.CssClass = "MyMexicoRowClass";
           }
     }
}


Thanks
Jayesh Goyani

0
mani
Top achievements
Rank 1
answered on 18 Apr 2015, 07:55 AM

Hi Jayesh,

This is working good, but can i know how to make this change with out touching .cs page? can i get this change in aspx page?

I am getting these details from the database. can i change these things in a stored procedure?

0
Peytton
Top achievements
Rank 1
answered on 28 Oct 2015, 08:01 AM

Hello Many
if you bring it from the database and in aspx page, you can do so

protected void Page_Load(object sender, EventArgs e)
{    
this.​full_grid.ItemDataBound += new GridItemEventHandler(​full_grid_ItemDataBound);
     this.full_grid.PreRender += new EventHandler(full_grid_PreRender);​
}​

0
Peytton
Top achievements
Rank 1
answered on 28 Oct 2015, 08:06 AM

Hello Many
if you bring it from the database and in aspx page, you can do so

protected void Page_Load(object sender, EventArgs e)
{    
     this.​full_grid.ItemDataBound += new GridItemEventHandler(​full_grid_ItemDataBound);
     this.full_grid.PreRender += new EventHandler(full_grid_PreRender);​
}​

  

code to fill grid

private void ​full_grid()

{

          BL_​Products bl = new BL_​Products();/*business layer*/

           this.grd_​Product.DataSource = bl.get​ProductEstado(); /*Call procedure */

            this.grd_Product.DataBind();     

   }​​​

 

changing color

void ​full_grid_ItemDataBound(object sender, GridItemEventArgs e)
         {
             if (e.Item is GridDataItem)
             {
                 /*Get the instance of the right type*/

                 GridDataItem dataBoundItem = e.Item as GridDataItem;

                 /*Check the formatting condition */
                 if (dataBoundItem["​state_p"].Text == "expired")
                 {
                     dataBoundItem["state_p""].ForeColor = System.Drawing.Color.Orange;
                     dataBoundItem["state_p""].Font.Bold = true;
                     /*e.Item.BackColor = System.Drawing.Color.LightGoldenrodYellow; */
                 }
                
             }
         }​

 

void full_grid_PreRender(object sender, EventArgs e)
         {
                 this.​full_grid.MasterTableView.Rebind();
         }​​

Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
mani
Top achievements
Rank 1
Peytton
Top achievements
Rank 1
Share this question
or