Solved

Adding date automatically to textbox when i select an item from drop down list

Posted on 2012-03-19
6
314 Views
Last Modified: 2012-03-21
I have a drop down list which has 3 items in it, i also have two Textboxes, Textbox1 and Textbox2. I want that when I select item1 from Dropdownlist and enter a date in Textbox1, The date in Textbox2 should be changed to 3years ahead of the date in Textbox1. Similarly when i select Item2 in dropdownlist and enter a date in Textbox1 the date in textbox2 should be automatically changed to (Textbox1 date+5years). I have the date in MM/DD/YYY format. Any ideas how to achive it using C# code. I know that I can use a stored procedure for this but I want to accomplish this using C# code.
0
Comment
Question by:skolanti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 37740005
0
 

Author Comment

by:skolanti
ID: 37742735
Hi, I am a beginner in ASP.Net web development, Can you provide me with sample code according to my Scenario?
0
 
LVL 29

Accepted Solution

by:
QPR earned 500 total points
ID: 37744496
aspx page:

 <asp:DropDownList ID="DropDownList1" runat="server"
    onselectedindexchanged="DropDownList1_SelectedIndexChanged"
        AutoPostBack="True">
        <asp:ListItem>Select</asp:ListItem>
        <asp:ListItem Value="3">3 years</asp:ListItem>
        <asp:ListItem Value="5">5 years</asp:ListItem>
    </asp:DropDownList>
    <p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </p>



aspx.cs page

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (TextBox1.Text != "")
        {
            DateTime GivenDate = Convert.ToDateTime(TextBox1.Text);

            if (DropDownList1.SelectedValue == "3")
            {
                TextBox2.Text = GivenDate.AddYears(3).ToString();
            }
            if (DropDownList1.SelectedValue == "5")
            {
                TextBox2.Text = GivenDate.AddYears(5).ToString();
            }
        }
    }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:skolanti
ID: 37747475
Thanks, This code worked but I had to make some changes based on my program.
0
 

Author Closing Comment

by:skolanti
ID: 37747488
Thanks, this code worked fine but I had to make some changes based on my Program logic.
0
 
LVL 29

Expert Comment

by:QPR
ID: 37749488
B is a bit unfriendly, I gave you the entire code needed to do what you needed... but thanks anyway
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET - Refactor Class per SOLID principles 2 43
WPF user control poped up from a window 1 51
How to force output to ascii 2 63
Set custom font WPF 2 26
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question