Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding days to current day being display

Status
Not open for further replies.

devondago

Programmer
Jan 22, 2003
38
US
I hope someone can help me with this one.
I have a page where there are 2 dropdownlist menus where you select a topic and if the topic is approved. Once those two criterias are met I display the results on a datagrid. example----
<asp:DataGrid ID="dg" Runat="server" Visible="False" Cellpadding="4" Autogeneratecolumns="false" allowSorting="true" OnSortCommand="dg_SortCommand">
<columns>
<asp:boundcolumn headertext="REQUESTED COMPLITED DATE" Datafield="datesubmit" DataFormatString="{0:d}" SortExpression="datesubmit" />
<asp:BoundColumn HeaderText="PRODUCT NAME" DataField="txtProductName" SortExpression="txtproductname" />
<asp:BoundColumn HeaderText="DEPARTMENT" DataField="deptname" SortExpression="deptname" />
<asp:HyperLinkColumn HeaderText="VIEW DETAILS" DataNavigateUrlField="reqid" DataNavigateUrlFormatString="CscReqDetails.aspx?reqid={0}"
Text="View Details" HeaderStyle-CssClass="RedLink"></asp:HyperLinkColumn>
</columns>
</asp:DataGrid>
As you can see the datagrid displays the date the form was submitted the product name, the department where the form was submitted from and a link to view the form result.
On the original form I have a radiobutton list that holds the value of 30 days 60 days or 90 days. This constitude the time the topic needs to be evaluated by.
(radiolist from original form submittion)
<asp:radiobuttonlist id="Time" Runat="server" RepeatDirection="Vertical">
<asp:ListItem Value="Standard (within 90 days)"></asp:ListItem>
<asp:ListItem Value="Escalated (within 60 days)"></asp:ListItem>
<asp:ListItem Value="Urgent (within 30 days)"></asp:ListItem>
</asp:radiobuttonlist>
I have now been asked to display on the datagrid the date the form was submitted + whatever the value was on the radiobutton selection. lets say I submitted the form on 5/1/2004 and i chose that the evaluation of my form needs to be completed on 30 days then I need to display 6/1/2004 as the date on the datagrid.
Problem is I tried addmonths function and cant get it to work. I am hoping someone can help me come up with a function for this. All help will be appreciated.
I tried the following but I keep getting only the date the form was submitted not the date + the completed date.
Sub GetDate()
Dim datesubmit As Date
Dim rdlTime As String

If rdlTime = "Standard (within 90 days)" Then
datesubmit = datesubmit.AddMonths(3)
End If

If rdlTime = "Escalated (within 60 days)" Then
datesubmit = datesubmit.AddMonths(2)
End If

If rdlTime = "Urgent (within 30 days)" Then
datesubmit = datesubmit.AddMonths(1)
Else
datesubmit = datesubmit
End If

End Sub

Thanks !
 
Take out that last Else and I think you will have it. the problem is it always executes when If rdlTime = "Urgent (within 30 days)" is false.


Greetings,
Dragonwell
 
I still dont get the desired results. any work around?
 
dev: The following worked fine with AddMonths:

Code:
Dim dteAdd As DateTime = txtDate.Text
txtDateAdd.Text = dteAdd.AddMonths(3)

..so it might be a casting problem.
 
devondago,
Can you post your real code - the code you posted earlier seems to be missing some important information that would help us debug your case. Like Isadore pointed out, I use DateTime and the AddMonths method works perfectly fine. It wouldn't be a casting problem, though, as that would just throw an exception as oppposed to giving you wrong results. Post the code on your GetDate() function so that we could see what the problem is.

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
got it working by changing the row on the datagrid to this
<asp:templatecolumn headertext="REQUESTED COMPLETION DATE"
SortExpression="datesubmit">
<ItemTemplate><%#GetDate(DataBinder.Eval(Container.DataItem,"datesubmit"),DataBinder.Eval(Container.DataItem,"rdlTime"))%></ItemTemplate>
</asp:TemplateColumn>
and the sub to a function.
Public Function GetDate(ByVal datesubmit As Date, ByVal rdltime As String) As String

rdltime = rdltime.Trim()
If rdltime = "Standard (within 90 days)" Then
datesubmit = datesubmit.AddMonths(3)
End If

If rdltime = "Escalated (within 60 days)" Then
datesubmit = datesubmit.AddMonths(2)
End If

If rdltime = "Urgent (within 30 days)" Then
datesubmit = datesubmit.AddMonths(1)

End If
datesubmit = datesubmit.ToShortDateString()
Return (datesubmit)
End Function
Thanks for the help....it got me to think. :) Fridays.aayy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top