Change RadGrid cell color based on flag

5 posts, 0 answers
  1. William
    William avatar
    22 posts
    Member since:
    May 2011

    Posted 16 Sep 2011 Link to this post

    HI Guys,

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

    William
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 16 Sep 2011 Link to this post

    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

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. mani
    mani avatar
    1 posts
    Member since:
    Apr 2015

    Posted 18 Apr 2015 in reply to Jayesh Goyani Link to this post

    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?

  5. Peytton
    Peytton avatar
    5 posts
    Member since:
    Oct 2015

    Posted 28 Oct 2015 in reply to mani Link to this post

    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);​
    }​

  6. Peytton
    Peytton avatar
    5 posts
    Member since:
    Oct 2015

    Posted 28 Oct 2015 Link to this post

    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();
             }​​

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017