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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to not display the a row based on a condition.

How to not display the a row based on a condition.

Scheduled Pinned Locked Moved C#
questioncssgraphicstutorial
11 Posts 5 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.
  • N Norris Chappell

    The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?

    protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
    {
    Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
    if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)

                {
                    e.Row.ForeColor = System.Drawing.Color.Red;
                }
            
                else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                {
                    e.Row.ForeColor = System.Drawing.Color.Orange;
                }
                else 
                    //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M))
                {
                    e.Row.Visible = false;
                }
    
    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #2

    If you are using a DataTable, you might want to try setting the RowFilter property of the DefaultView.

    N 1 Reply Last reply
    0
    • N Norris Chappell

      The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?

      protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
      {
      Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
      if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)

                  {
                      e.Row.ForeColor = System.Drawing.Color.Red;
                  }
              
                  else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                  {
                      e.Row.ForeColor = System.Drawing.Color.Orange;
                  }
                  else 
                      //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M))
                  {
                      e.Row.Visible = false;
                  }
      
      M Offline
      M Offline
      Mathi Mani
      wrote on last edited by
      #3

      If that row is not required, then filter it while getting the data from your data source. So you can avoid all these at code level in C#.

      N 1 Reply Last reply
      0
      • N Norris Chappell

        The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?

        protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
        {
        Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
        if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)

                    {
                        e.Row.ForeColor = System.Drawing.Color.Red;
                    }
                
                    else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                    {
                        e.Row.ForeColor = System.Drawing.Color.Orange;
                    }
                    else 
                        //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M))
                    {
                        e.Row.Visible = false;
                    }
        
        A Offline
        A Offline
        Agent__007
        wrote on last edited by
        #4

        Norris Chappell wrote:

        Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015

        Which one's ActualFTE in these, and what's with the Label lst?

        You have just been Sharapova'd.

        1 Reply Last reply
        0
        • N Norris Chappell

          The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?

          protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
          {
          for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
          {
          Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
          if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)

                      {
                          e.Row.ForeColor = System.Drawing.Color.Red;
                      }
                  
                      else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                      {
                          e.Row.ForeColor = System.Drawing.Color.Orange;
                      }
                      else 
                          //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M))
                      {
                          e.Row.Visible = false;
                      }
          
          A Offline
          A Offline
          Agent__007
          wrote on last edited by
          #5

          Norris Chappell wrote:

          Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015

          Which one's ActualFTE among these, and what's with the Label lst?

          You have just been Sharapova'd.

          1 Reply Last reply
          0
          • M Mathi Mani

            If that row is not required, then filter it while getting the data from your data source. So you can avoid all these at code level in C#.

            N Offline
            N Offline
            Norris Chappell
            wrote on last edited by
            #6

            I changed my sql but it now showing the first row which is < .075 as black not yellow. The rest of the rows are correct. Bair James S 176.0000 1.0000 128.0000 0.7300 04/01/2015

            1 Reply Last reply
            0
            • P PIEBALDconsult

              If you are using a DataTable, you might want to try setting the RowFilter property of the DefaultView.

              N Offline
              N Offline
              Norris Chappell
              wrote on last edited by
              #7

              Can you Please explain what that means? I'm now getting all of the rows I want but the very first record is not Yellow which is less than .075. All o the remaining rows are correct.

              1 Reply Last reply
              0
              • N Norris Chappell

                The first record is displaying, I only wanted to show rows with more 1.25 and less .075. Doe John 176.0000 1.0000 165.0000 0.9400 04/01/2015 This first row is the culprit. What is wrong with my code?

                protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
                {
                for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
                {
                Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
                if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)

                            {
                                e.Row.ForeColor = System.Drawing.Color.Red;
                            }
                        
                            else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                            {
                                e.Row.ForeColor = System.Drawing.Color.Orange;
                            }
                            else 
                                //if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > .74M && (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < 1.25M))
                            {
                                e.Row.Visible = false;
                            }
                
                A Offline
                A Offline
                Agent__007
                wrote on last edited by
                #8

                Sorry for the delayed reply, I don't check the inbox linked with this account too often. I think you might have resolved this issue already, but - ;) If the ActualFTE is 0.7300, as you have mentioned in the email, the row should have been highlighted in Orange color? If that's "not" the case, are you sure you still have the else if condition < .75M in place and it's really not < .075 by any chance (from what you have mentioned in your original post)? Also, can you check what you are getting from Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) using immediate window/quick watch and a debug point?

                You have just been Sharapova'd.

                N 1 Reply Last reply
                0
                • A Agent__007

                  Sorry for the delayed reply, I don't check the inbox linked with this account too often. I think you might have resolved this issue already, but - ;) If the ActualFTE is 0.7300, as you have mentioned in the email, the row should have been highlighted in Orange color? If that's "not" the case, are you sure you still have the else if condition < .75M in place and it's really not < .075 by any chance (from what you have mentioned in your original post)? Also, can you check what you are getting from Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) using immediate window/quick watch and a debug point?

                  You have just been Sharapova'd.

                  N Offline
                  N Offline
                  Norris Chappell
                  wrote on last edited by
                  #9

                  protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
                  {
                  for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
                  {
                  // Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
                  if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                  // if (Convert.ToDecimal(last.Text) > 1.25M)
                  {
                  e.Row.ForeColor = System.Drawing.Color.Orange;
                  }
                  // else if (Convert.ToDecimal(last.Text) < .75M)
                  else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)
                  {
                  e.Row.ForeColor = System.Drawing.Color.Red;
                  }

                  The conditions are working properly. It is the fact that the very first record is not changing to Orange even though it is < .075

                  Richard DeemingR 1 Reply Last reply
                  0
                  • N Norris Chappell

                    protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
                    {
                    for (int i = 0; i <= gvCATW.Rows.Count - 1; i++)
                    {
                    // Label last = (Label)gvCATW.Rows[i].FindControl("lblActualFTE");
                    if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) < .75M)
                    // if (Convert.ToDecimal(last.Text) > 1.25M)
                    {
                    e.Row.ForeColor = System.Drawing.Color.Orange;
                    }
                    // else if (Convert.ToDecimal(last.Text) < .75M)
                    else if (Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE")) > 1.25M)
                    {
                    e.Row.ForeColor = System.Drawing.Color.Red;
                    }

                    The conditions are working properly. It is the fact that the very first record is not changing to Orange even though it is < .075

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #10

                    There's no need to loop over all the rows - the RowDataBound event will fire for each row. Try changing your code to:

                    protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
                    {
                    decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
                    if (actualFTE < .75M)
                    {
                    e.Row.ForeColor = System.Drawing.Color.Orange;
                    }
                    else if (actualFTE > 1.25M)
                    {
                    e.Row.ForeColor = System.Drawing.Color.Red;
                    }
                    }

                    If it still doesn't work, check the HTML source to see what's rendered for the first row. You might want to add the ActualFTE to the row as a data- attribute, to make sure the value is what you're expecting:

                    decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
                    e.Row.Attributes.Add("data-actual-fte", actualFTE.ToString());
                    ...


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    N 1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      There's no need to loop over all the rows - the RowDataBound event will fire for each row. Try changing your code to:

                      protected void gvCATW_RowDataBound(object sender, GridViewRowEventArgs e)
                      {
                      decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
                      if (actualFTE < .75M)
                      {
                      e.Row.ForeColor = System.Drawing.Color.Orange;
                      }
                      else if (actualFTE > 1.25M)
                      {
                      e.Row.ForeColor = System.Drawing.Color.Red;
                      }
                      }

                      If it still doesn't work, check the HTML source to see what's rendered for the first row. You might want to add the ActualFTE to the row as a data- attribute, to make sure the value is what you're expecting:

                      decimal actualFTE = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ActualFTE"));
                      e.Row.Attributes.Add("data-actual-fte", actualFTE.ToString());
                      ...


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      N Offline
                      N Offline
                      Norris Chappell
                      wrote on last edited by
                      #11

                      Thanks. That worked. Is now doing what they want.

                      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