Forms Data Controls :: GridView DateDiff Negative Value
Apr 8, 2010
I have a GridView that populates the days between the start and end date. What i want to ask is that is it possible to display a word "Overdue" (If possible "Overdue by 7 days") when the datediff is negative (eg: -7 days) The following are parts my codes for now:
<asp:TemplateField HeaderText="Date Raised" SortExpression="DateRaised">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DateRaised","{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Expected Close Date" SortExpression="DateClose">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DateClose","{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DaysTaken" HeaderText="Allocated Days" />
<asp:BoundField DataField="RemainingDays" HeaderText="Remaining Days" />
<asp:SqlDataSource ID="SqlDS_UnresolvedIssues" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString_PITLog %>"
SelectCommand="SELECT [IssueLog].[DateRaised], [IssueLog].[DateClose], DATEDIFF(dd,DateRaised,DateClose) AS DaysTaken, DATEDIFF(dd, GETDATE() ,DateClose) AS RemainingDays FROM [IssueLog]
INNER JOIN [ActDetails] ON [IssueLog].[ActID]=[ActDetails].[ActID] WHERE [ActDetails].[ProjID]=@ProjID AND [ActDetails].[DevPhase]=@DevPhase AND NOT [IssueLog].[IssueStatus]=@IssueStatus">
<SelectParameters>
<asp:ControlParameter ControlID="DD_PMProjID" Name="ProjID" />
<asp:ControlParameter ControlID="DD_DevPhase" Name="DevPhase" />
<asp:Parameter DefaultValue="COMP" Name="IssueStatus" />
</SelectParameters>
</asp:SqlDataSource>
By the way, I am using Web Developer 2008, VB.net.
View 11 Replies
Similar Messages:
Jul 29, 2010
I have the following problem, i am using gridview to display some table info,, and during RowDataBound event i am binding another DataList control placed on gridview template column,,, the problem is that the DataBind() event of the gridview gives "Index 1 is either negative or above rows count." error.
I debugged alot,, when you disable the DataList binding it works,, but why the 2 not working together i dont know!!.
Below my Code in
Code Behind:
using System;
View 4 Replies
Jan 26, 2011
I have gridview like this.
[Code]....
is index was out of range must be non negative and less than the size of the collection
View 7 Replies
Dec 13, 2010
I have a gridview that displays the total hours and employee works. I also have another column in the gridview that shows the difference from the hours worked and 8.5. I want the column that shows the difference to display the number in red whenever the number is a negative.
The gridview looks like:
Time In
Time Out
Hours Worked
Difference
7:30:00 AM
3:58:00 PM
8.47
-0.03
I would like it to look like:
Time In
Time Out
Hours Worked
Difference
7:30:00 AM
3:58:00 PM
8.47
-0.03
View 20 Replies
Aug 6, 2010
I have a gridview that calculate net balance by taking deposit - withdraw. So when the withdraw is more than the deposit, it will result in a negative value, how do I detect that and replace the minus sign with bracket?
[code]....
View 10 Replies
May 20, 2010
This is my first attempt at paging on a listview. The first time my page loads it loads the listview fine, but when I try to use the paging I get the following error:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Here's my code:
[code].....
When I take the following line out I don't get the error, but i need it to populate my controls:
DataKey currentDataKey = this.lvReports.DataKeys[currentItem.DataItemIndex];
View 8 Replies
Mar 1, 2011
i am trying to do a really simple thing but it won't work...
[Code]....
this is the error i get
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
i can see different columns in gridview but when hidding gives me error
View 1 Replies
Aug 7, 2012
I have my grid view and its code is as follows
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewCampaign.aspx.cs" Inherits="NoticeBoard.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">
<title></title> <style type="text/css"> .style1
[Code] .....
Basically it is the form when user enter all the data and press the submit button then the data will appear on the grid view . On grid view there is option edit when i edit the row and press the update button then the following error will occur
int cid = Int32.Parse(noticeDetails.DataKeys[e.RowIndex].Value.ToString());
"Argumentout of range exception and was unhandled by user code.
Index was out of range must be non negative and out of collection
the aspx.cs code0
View 1 Replies
Jun 17, 2010
I am trying to write some SQL to populate a gridview.
The sql should print out 3 columns:
Name, County, LastCollection (the amount of days since the last collection)
I have previously calculated the amount of days since last collection individually like this:
[Code]....
But am stuck on doing it for more than 1 record to populate the gridview which should show all the records and their last collection date.
View 9 Replies
Jan 15, 2010
i'm very new to this world, and trying to develope a system that calculates Holidays. I want to exclude saturdays and sunday but it doesnt.
[code]...
View 1 Replies
Sep 23, 2010
This is my query.I am trying to figure out after the case statement
[code]...
How come I cannot get anything out of this?? I am trying how many days after more than 2 days.... Is there a way to do this?
[code]...
View 3 Replies
Feb 23, 2010
I had a repeater that will be binded using dataset
[Code]....
and on page load I write this code
[Code]....
it worked very well on my machine , after applying it on the server it give the following error
Server Error in '/' Application.
Number must be either non-negative or -1. Parameter name: millisecondsTimeout Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Number must be either non-negative or -1. Parameter name: millisecondsTimeoutSource Error:
[Code]....
Stack Trace:
[Code]....
View 3 Replies
Sep 3, 2010
my app requires an elapsed time calculation that I have done like this
CONVERT(Varchar, (DATEPART(dd, GETDATE() - DateAdded)-1) * 24 +
DATEPART(hh,GETDATE() - DateAdded)) + 'h:' + CONVERT(Varchar, DATEPART(mi, GETDATE() - DateAdded)) + 'm' AS ElapsedTime
This works.. I can then colour my grid view cells accordingly using the substring function.. the problem is that I have been told that using GETDATE three times is not a good use of resources, is it possible to use the Datediff function to get the same result?
View 3 Replies
Jan 31, 2011
I have to believe that I'm just missing something silly on this one. It SHOULD work... but alas, it is not. Here is my code:
SELECT s.[id], s.[familyid], s.[lastname], s.[firstname], s.[middlename], s.[suffix], s.[nickname], s.[dob], fix(datediff(d, isnull(s.DOB, Now()), NOW()) / 365) as AGE, s.[allergies], s.[notes], s.[photographsOK], s.[school], f.[city], f.[state] FROM [Students] s, [families] f, [employee] e where s.[familyid] = f.[id] and f.[franchise] = e.[franchisename] and e.[username] = @Username order by f.[lastname]"
This was working fine before I put the "IsNull"handler in the datediff function to handle problems with null dates. Now I get the following error when I try to run it.Wrong number of arguments used with function in query expression 'fix(datediff('d', isnull(s.[DOB], now()), NOW()) / 365)'. I even tried using just the ISNULL(s.[DOB], NOW()) without the Datediff and get the same error.
View 5 Replies
Jan 21, 2010
I have encountered a problem about "order by" sorting in SQL. As some of the items (strings) in a dropdown list contain negative sign on the left, it is surprising for me that the SQL server cannot sort the items in an alphabetical order and as a result I was forced to set the property value (IsSort = False) of the Ajax ListSearch, which slow down the searching speed a lot. Below are examples of two of the string items with a negative sign on the left.
View 6 Replies
Oct 19, 2010
I have the following issue where I cannot seem to display a negative number and the result seems to stay on zero.
The code is as follows:
[code]...
In my code iNumber1 = 108 and iNumber2=27 however when the result is divided again by 108 the answer seems to stay on 108. I tried using doubles but with no luck.
View 3 Replies
Jan 24, 2016
How to convert negative value (-) to 0 using C# and VB.Net? Below is my sample query:
dim finaltotalbonus as doubledim Sumtotalbonus as doubledim totaldeductamount as double
finaltotalbonus = Math.Round(Sumtotalbonus - totaldeductamount)FinalTotal = finaltotalbonus
sample data :
finaltotalbonus = Math.Round(200 - 500)FinalTotal = -300
How to make system show FinalTotal = 0 for negative value (-)?
View 1 Replies
Jun 1, 2012
Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index after binding the gridview with data i need to set the column width as defined in a array.i am setting it as
string[] cwidth = Session["width"].ToString().Split(',');
int colcount = coln.Length;
for (int i = 0; i <= colcount - 1; i++)
{
Gridview1.Columns[i].HeaderText = coln[i].ToString();
int swidth = Convert.ToInt32(cwidth[i]);
Gridview1.Columns[i].HeaderStyle.Width = Convert.ToInt32(cwidth[i]);
}
but i get the above error
View 1 Replies
Feb 2, 2012
I have an array called"List" with 1 item and a gridview "grdWorkingDays" with two columns.
In the First column, I want to display the working days dynamically from the arraylist and in the second column I need to display a dropdown with CL/PL/Halfday(Which has values from a database table and is already written in a method) against each date of array list.
The code is:
int NoOfWorkingDays = List.Count;
for (int j = 0; j < NoOfWorkingDays; j++){
String Date = ((Label)grdWorkingDays.Rows[j].Cells[0].FindControl("lblLeaveType")).Text;
Date = List[j].ToString();
[Code] .....
When I run this, I am getting error as:
"Index was out of range. Must be non-negative and less than the size of the collection." pointing to the 1st row of for loop.
I am struggling with this for past few days and count find what the error is.
FYI, the array count is being calculated correctly as "1" .
View 1 Replies
May 7, 2015
I want to put validation in a Textbox, that the numbers entered inside textbox should be between 1 to -1 only i.e., (-1, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7 ....... 1 )I tried below code but "RangeValidator" is not working as per requirement:
HTML:
<asp:RangeValidator ID="RangeValidator1" runat="server" MaximumValue="1" MinimumValue="-1" Text="value between 1 to -1" ErrorMessage="value between 1 to -1" ControlToValidate="TxtY" ValidationGroup="usrvalid"></asp:RangeValidator>
<asp:TextBox ID="TxtY" Text='<%#Eval("Y") %>' runat="server" Width="30%"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender5" TargetControlID="TxtY" FilterType="Custom" ValidChars="-01234567890." runat="server"></cc1:FilteredTextBoxExtender>
How to achieve it.
View 1 Replies
Aug 18, 2010
I retrieve data from databse
col1 col2 col3
0 0 1,000
1 0 0
0 1 5
0 -1,200 0
0 0 0
0 0 0
and now I want to sum each for total
[code]....
I will get error when dr["col2"].ToString() = -1,200
col2 += Int32.Parse(dr["col2"].ToString().Replace(",",""),NumberStyles.AllowDecimalPoint);
does the problem is the negative sign?
how to sum for negative number?
View 9 Replies
Sep 7, 2010
I have negative numbers in my report and I wish to display them with a "<" sign.
View 5 Replies
Oct 25, 2010
i have a select statement below. The result of r1- @r1 may be positive or negative.
i want it to always result as positive, so it is a negative number then it to show the same number as positive. can i do this?
e.g.
r1 = 7, @r1 = 4
r1 - @r1 = 3
but
if r1 = 5, @r1 = 6
r1 = @r1 = -1, but i want this to be 1, because i am trying to work out the difference between the two numbers.
can this be done within a select statement? my select statement is:
SELECT imageurl, (r1 - @r1) AS difference
View 1 Replies
Mar 29, 2011
I have a situation wherein I need to search through a VS project for any control that does not have a MaxLength property defined.For example:
<asp:TextBox ID="txtName" runat="server" MaxLength="50" Text="Enter Name" />
<asp:TextBox ID="txtOther" MaxLength="25" runat="server" />
<asp:TextBox ID="MaxLength" runat="server" />
[code]...
View 2 Replies
Feb 24, 2011
I am Getting this exception when i select the checkbox control in Grid view"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
I have Checkbox in Gridview control, when i select the record in grid view corresponding entire record will be populated into form fields,it working absolutely fine,I have search method on my webform, if i searched based on particular value in form fileds, records will be filtered in Girdvie control when i select the record, same reocrd suppose to populate in form fields but not loading, above error occuring.normally no issues error occuring when i search and select record. error occuring at redline in the code
[code].....
View 3 Replies