473,499 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error with conditional logic on ASP.Net GridView

5 New Member
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!

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. DateTime data = DateTime.Now; //will give time for today
  4.  
  5. protected void grid_RowDataBound(Object sender, GridViewRowEventArgs e)
  6. {
  7.  
  8.  if(e.Row.RowType == DataControlRowType.DataRow)
  9.  {
  10.    if((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes<=15)
  11.        e.Row.BackColor = System.Drawing.Color.Red;
  12.    else if ((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes >15<=30)
  13.        e.Row.BackColor = System.Drawing.Color.yellow;
  14.  else if ((DateTime.Now - DateTime.Parse((e.Row.DataItem as DataRowView)["scheduledTime "])).TotalMinutes >30<120)
  15.        e.Row.BackColor = System.Drawing.Color.green
  16. }
  17. }
  18.  
  19.  
Jan 2 '13 #1
3 1752
Rabbit
12,516 Recognized Expert Moderator MVP
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?
Jan 3 '13 #2
crh313
5 New Member
@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?
Jan 7 '13 #3
Frinavale
9,735 Recognized Expert Moderator Expert
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
Jan 8 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2251
by: Rasika WIJAYARATNE | last post by:
Hi I have bound data to a Repeater control. How can I do something like this (below is the desired logic only, it doesn't actually work): <ItemTemplate> <%if...
2
1547
by: booksnore | last post by:
..eh I was stuck thinking up a subject title for this post for a while.. So I am processing a really big file (scary big). Each record is fixed length, I need to test conditions on certain fields...
2
2131
by: Anonieko | last post by:
Hello ASPNET guru's, What is a clean way to go around the problem of displaying a GridView templated column where data can contain Single Quote ( ' )? I maybe too naive, but this is of course...
4
11094
by: Dabbler | last post by:
I'm trying to replace a user code in data column with user friendly text for a GridView ItemTemplate as in: Text='<%# Eval("LocationType")%> == "P" ? "Pickup" : "DropOff"' However the value...
0
1063
by: Jon Paal | last post by:
why am I getting this error ? ID field is identity, type int Error message on update ============================ Incorrect syntax near 'nvarchar'. Must declare the scalar variable "@id". ...
6
1797
by: blknav01 | last post by:
Greetings all. I am having a problem with getting java program to produce the correct output. I am being asked to use conditional logic to determine a tax rate category. I am not getting any...
1
1646
by: mikebrengartner | last post by:
Hi all, I've got a data bound list view that I'm trying to work with. I'm trying to fill out the item template with a table row that displays a link to a file if the job status is complete. I've...
6
4021
by: vijeberal | last post by:
Hi all, I am working on a GridView and there exist a Checkbox control .. iplaced another checkbox in header also i have written a javascript for selection of checkboxex fro e.g if you click on...
2
2363
by: SK2010 | last post by:
I have a gridview with edit and delete. When i click Edit, I donot get all the textboxes. I just get 1. on top of that, when I try to update anything in that textbox, I get object Reference not set...
0
1227
by: ramuksasi | last post by:
Hi, I've an asp.net .ascx form and a gridview on that form.I've placed that form on an .aspx. Now while I'm trying to import data from gridview to excel it is showing the error "Control 'GridView'...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.