What is the error you are seeing?
Jim
Main Topics
Browse All TopicsHi
I need help calculating the end date based on the number of weeks entered. I am using datagrid.Please see the code below:
I am keep getting error. Also, I am not so sure whether shud I do this on the client side or do it in the code behind. Any help is appreicated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi Jim
I tried your code and getting the following errors:
Error 1 Cannot convert null to 'System.DateTime' because it is a value type
Error 2 Cannot implicitly convert type 'string' to 'System.DateTime'
Error 3 The name 'txtDateEnd' does not exist in the current context
Any help is appreicated.
My Code:
protected void TextBox_Changed(object sender, EventArgs e)
{
int intWeeks = 0;
foreach (DataGridItem item in dgPhaseDisplay.Items)
{
TextBox txtWeeks = (TextBox)item.FindControl(
TextBox endDateTB = (TextBox)item.FindControl(
TextBox startDateTB = (TextBox)item.FindControl(
if (startDateTB == null)
throw new Exception("Unable to locate startDate textbox.");
if (endDateTB == null)
throw new Exception("Unable to locate endDate textbox.");
DateTime txtStartDate = DateTime.Parse(startDateTB
DateTime endDate = null;
if ((txtWeeks == null) || !int.TryParse(txtWeeks.Tex
{
SetValidationErrorMessage(
}
else
{
endDate = Convert.ToDateTime(txtStar
txtDateEnd.Text = endDate.ToString();
}
}
}
--ASP.Net Code:
<asp:datagrid ID="dgPhaseDisplay" HeaderStyle-Font-Size="x-s
AlternatingItemStyle-CssCl
CellPadding="1" CellSpacing="1" HeaderStyle-BackColor="Lig
PagerStyle-VerticalAlign="
<AlternatingItemStyle CssClass="smallcolor1" ></AlternatingItemStyle>
<ItemStyle CssClass="smallcolor2" VerticalAlign="Top" Wrap="True"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" VerticalAlign="Bottom" BackColor="LightBlue"></He
<Columns>
<asp:TemplateColumn HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="dgChkBox" runat="server" Checked="false" />
</ItemTemplate>
<ItemStyle Width="75px" />
<HeaderStyle Width="75px" />
</asp:TemplateColumn>
<asp:BoundColumn DataField="lnkPhaseID" Visible="False" HeaderText="Phase ID" SortExpression="lnkPhaseID
<asp:BoundColumn DataField="lnkPhaseDescp" HeaderText="Phase Descp" SortExpression="lnkPhaseDe
<ItemStyle Width="250px" />
<FooterStyle Font-Size="X-Small" />
<HeaderStyle Width="250px" />
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Start Date">
<ItemTemplate>
<peterCC:DateTextBox ID="txtDateStart" runat="server" xEnableContextMenuB="False
<xPopupCalendar xToggleImageUrl="PetersDat
</peterCC:DateTextBox>
</ItemTemplate>
<ItemStyle Width="75px" />
<HeaderStyle Width="75px" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="# Weeks">
<ItemTemplate>
<asp:TextBox ID="txNoWeeks" runat="server" Text="" Width="30px" MaxLength="4" AutoPostBack="true"
OnTextChanged="TextBox_Cha
</ItemTemplate>
<ItemStyle Width="75px" />
<HeaderStyle Width="75px" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="End Date">
<ItemTemplate>
<peterCC:DateTextBox ID="txtDateEnd" runat="server" xEnableContextMenuB="False
<xPopupCalendar xToggleImageUrl="PetersDat
</peterCC:DateTextBox>
</ItemTemplate>
<ItemStyle Width="75px" />
<HeaderStyle Width="75px" />
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Alias Descp">
<ItemTemplate>
<asp:TextBox ID="txtPhaseAlias" runat="server" Text=""></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:TemplateColumn>
</Columns>
<PagerStyle VerticalAlign="Top" />
</asp:datagrid>
</td>
</tr>
Jim
I solved the problem.
Thanks for your help. You guys are the best.
Just FYI.. Take a look at the code:
protected void TextBox_Changed(object sender, EventArgs e)
{
int intWeeks = 0;
foreach (DataGridItem item in dgPhaseDisplay.Items)
{
TextBox txtWeeks = (TextBox)item.FindControl(
TextBox endDateTB = (TextBox)item.FindControl(
TextBox startDateTB = (TextBox)item.FindControl(
if (startDateTB == null)
throw new Exception("Unable to locate startDate textbox.");
if (endDateTB == null)
throw new Exception("Unable to locate endDate textbox.");
if (startDateTB.Text != "")
{
DateTime txtStartDate = DateTime.Parse(startDateTB
if ((txtWeeks == null) || !int.TryParse(txtWeeks.Tex
{
SetValidationErrorMessage(
}
else
{
int numberofdays = 0;
switch (txtStartDate.DayOfWeek)
{
case DayOfWeek.Monday:
{
numberofdays = 3 + (intWeeks * 7);
break;
}
case DayOfWeek.Tuesday:
{
numberofdays = 3 + (intWeeks * 7);
break;
}
case DayOfWeek.Wednesday:
{
numberofdays = 3 + (intWeeks * 7);
break;
}
case DayOfWeek.Thursday:
{
numberofdays = 4 + (intWeeks * 7);
break;
}
case DayOfWeek.Friday:
{
numberofdays = 3 + (intWeeks * 7);
break;
}
case DayOfWeek.Saturday:
{
numberofdays = 2 + (intWeeks * 7);
break;
}
case DayOfWeek.Sunday:
{
numberofdays = 1 + (intWeeks * 7);
break;
}
}
string strEndDate = Convert.ToDateTime(txtStar
endDateTB.Text = strEndDate.ToString();
}
}
}
}
Business Accounts
Answer for Membership
by: rajeshsachdevaPosted on 2008-02-01 at 10:44:33ID: 20799293
Please Help!