Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Changing color on Boundfield text content

Changing color on Boundfield text content

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lvq684
    wrote on last edited by
    #1

    Hi. I have this updatepanel, with some fields that are getting filled from an ObjectDataSource. One of the fiels are a date, and i want this date to be marked as red (and maybe in bold) if the date is one day from today or later. Problem is, I have no clue on how to do this, since I am new to asp.net! So is there a way to add a method that changes this specific ItemStyle-ForeColor based on the content i get from my datalayer? This is my updatepanel:

    Thanks alot!

    S 1 Reply Last reply
    0
    • L lvq684

      Hi. I have this updatepanel, with some fields that are getting filled from an ObjectDataSource. One of the fiels are a date, and i want this date to be marked as red (and maybe in bold) if the date is one day from today or later. Problem is, I have no clue on how to do this, since I am new to asp.net! So is there a way to add a method that changes this specific ItemStyle-ForeColor based on the content i get from my datalayer? This is my updatepanel:

      Thanks alot!

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      lvq684 wrote:

      I have this updatepanel

      It does not matter in your case.

      lvq684 wrote:

      i want this date to be marked as red (and maybe in bold) if the date is one day from today or later

      You need to use RowDataBound of GridView for this.

      protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
      DataControlRowType rtype = e.Row.RowType;
      if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
      && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
      && rtype != DataControlRowType.Pager)
      {
      //Logic to get the color needed to be shown
      Calendar cd = e.Row.FindControl("myCal") as Calendar;
      //Set whatever color you need to!
      cd.ForeColor = Color.Red;
      }
      }

      L 1 Reply Last reply
      0
      • S Sandeep Mewara

        lvq684 wrote:

        I have this updatepanel

        It does not matter in your case.

        lvq684 wrote:

        i want this date to be marked as red (and maybe in bold) if the date is one day from today or later

        You need to use RowDataBound of GridView for this.

        protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
        {
        DataControlRowType rtype = e.Row.RowType;
        if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
        && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
        && rtype != DataControlRowType.Pager)
        {
        //Logic to get the color needed to be shown
        Calendar cd = e.Row.FindControl("myCal") as Calendar;
        //Set whatever color you need to!
        cd.ForeColor = Color.Red;
        }
        }

        L Offline
        L Offline
        lvq684
        wrote on last edited by
        #3

        Thanks alot for your answer, but I dont quite follow the code. Whats up with the

        Calendar cd = e.Row.FindControl("myCal") as Calendar;

        And could you please paste the corresponding .aspx code for the Gridview please? I am very grateful!

        S 1 Reply Last reply
        0
        • L lvq684

          Thanks alot for your answer, but I dont quite follow the code. Whats up with the

          Calendar cd = e.Row.FindControl("myCal") as Calendar;

          And could you please paste the corresponding .aspx code for the Gridview please? I am very grateful!

          S Offline
          S Offline
          Sandeep Mewara
          wrote on last edited by
          #4

          I believe what i have provided is more than enough.

          lvq684 wrote:

          could you please paste the corresponding .aspx code

          No! i wouldn't

          lvq684 wrote:

          but I dont quite follow the code

          You said you have a calendar inside the grid, so that line gets the calendar control to you. Looks like you are a fresher. Would suggest you to read book first.

          L 1 Reply Last reply
          0
          • S Sandeep Mewara

            I believe what i have provided is more than enough.

            lvq684 wrote:

            could you please paste the corresponding .aspx code

            No! i wouldn't

            lvq684 wrote:

            but I dont quite follow the code

            You said you have a calendar inside the grid, so that line gets the calendar control to you. Looks like you are a fresher. Would suggest you to read book first.

            L Offline
            L Offline
            lvq684
            wrote on last edited by
            #5

            Yes, as stated in the first post, I am new to asp.net. It´s not a calendar but a simple string which holds the date. The date sorting is being issued elsewhere. But I´ll try changing the calendar to a string and fiddle with it. Question is just how the page control calls this method. I will google some more. Thanks.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups