Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my asp.net Application there is a dropdownList named "ddlWarrenty" Where have some hard coded item such as
'1 Year'
'2 Year'
etc.
Also two textbox named 'dptPurchaseDate' and 'dptPurchaseDateEx'
My expectation is that when user select '1 Year' from 'ddlWarrenty' and input a datetime in
'dptPurchaseDate' then 'dptPurchaseDateEx' will be show a date by adding 'ddlWarrenty' and
'dptPurchaseDate'

I have tried this in the following way. But it does not work. I wrote the code in the textchanged event of dptPurchaseDate

C#
if(ddlWarrenty.SelectedItem.Text.Trim() == "1 Year")
{
      DateTime dtday = Convert.ToDateTime(dptPurchaseDate.Text.Trim());
      dptPurchaseDateEx.Text = (Convert.ToInt32(dtday) +         Convert.ToInt32(dtday.AddYears(1))).ToString();
}
Posted
Updated 12-May-13 18:58pm
v4
Comments
_Amy 13-May-13 0:10am    
Your expectation is in Windows application or web application?
Sumon562 13-May-13 0:12am    
Web Application

1 solution

Use OnSelectedIndexChanged event of DropDownList. Try this:
C#
protected void ddlWarrenty_SelectedIndexChanged(object sender, EventArgs e)
{
    if(ddlWarrenty.SelectedItem.Text.Trim() == "1 Year")
    {
          DateTime dtday = Convert.ToDateTime(dptPurchaseDate.Text.Trim());
          dptPurchaseDateEx.Text = (Convert.ToInt32(dtday) +         Convert.ToInt32(dtday.AddYears(1))).ToString();
    }
}


--Amit
 
Share this answer
 
Comments
Sumon562 13-May-13 1:41am    
Thank you Mr._Amy. I have tried but it does not work.
_Amy 13-May-13 2:21am    
Check AutoPostBack property of your DropDownList and set it to true.
Sumon562 14-May-13 1:01am    
Thank you Mr. _Amy. It works nicely
_Amy 14-May-13 1:23am    
Welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900