Error with conditional logic on ASP.Net GridView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crh313
    New Member
    • Dec 2012
    • 5

    #1

    Error with conditional logic on ASP.Net GridView

    Hello All,

    I am using a C# condition that changes the row backcolor of a Gridview based on the scheduled time value(TIMESTAMP ). I am new to C# and could use some help with my code. Thanks!

    Code:
    
    DateTime data = DateTime.Now; //will give time for today
    
    protected void grid_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
    
     if(e.Row.RowType == DataControlRowType.DataRow)
     {
       if((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes<=15)
           e.Row.BackColor = System.Drawing.Color.Red;
       else if ((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes >15<=30)
           e.Row.BackColor = System.Drawing.Color.yellow;
     else if ((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes >30<120)
           e.Row.BackColor = System.Drawing.Color.green
    }
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You haven't told us what the problem is. Are you getting errors? What are they? Is it not doing what you expect? What is it supposed to do? What is it doing instead?

    Comment

    • crh313
      New Member
      • Dec 2012
      • 5

      #3
      @Rabbit,

      I think the first issue is that I dont have the function linked to my object correctly. I have some C# files on the server-side, and need to create another C# file for this event. How can I link a external event to the object in the main aspx file?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Sorry, what is the problem?

        That event should be directly tied to the grid that it is implemented for. I don't understand where this "other C# file" comes into play.

        -Frinny

        Comment

        Working...