Click here to Skip to main content
14,698,142 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
validate the dropdownlist date


Design as follows



Date1 dropdownlist(in dropdownlist dates are retrived from the database)
Date2 dropdownlist(in dropdownlist dates are retrived from the database)
Date3 dropdownlist(in dropdownlist dates are retrived from the database)
Date4 dropdownlist(in dropdownlist dates are retrived from the database)



i want to show the message Date1 and Date2 is the next date of Date3 and Date4


suppose user select the date in dropdownlist as follows

Date1 9 Aug 2013
Date2 9 Aug 2013

Date3 6 Aug 2013
Date4 6 Aug 2013

i want to show the message Date1 and Date2 is the next date of Date3 and Date4


i want the output as follows, the following is the correct output.

Date1 7 Aug 2013
Date2 7 Aug 2013

Date3 6 Aug 2013
Date4 6 Aug 2013


for that how can i do using asp.net csharp.


Rgds,
Narasiman P.
Posted
Comments
[no name] 2-Aug-13 6:00am
   
Could you please be more clear on your question ?
Lakshmimsridhar 2-Aug-13 6:30am
   
String Month = DateTime.Now.Month.ToString();
String Year = DateTime.Now.Year.ToString();


u can take month and year separately. i hope it will help u

1 solution

Hi,
Check below. Is this want you?

DateTime Date1 = Convert.ToDateTime(ddlDate1.SelectedValue);
DateTime Date2 = Convert.ToDateTime(ddlDate2.SelectedValue);
DateTime Date3 = Convert.ToDateTime(ddlDate3.SelectedValue);
DateTime Date4 = Convert.ToDateTime(ddlDate4.SelectedValue);

string d1,d2,d3,d4;

if(Date3.AddDays(1)== Date1)
{ // validation true

   // store direct dropdown value because it is already in "d MMM yyyy" format
   d1 = ddlDate1.SelectedValue;
   d3 = ddlDate3.SelectedValue;

   // if dropdown is not in "d MMM yyyy" format
   d1 = Date1.toString("d MMM yyyy");
   d3 = Date3.toString("d MMM yyyy");
}
else
{
   // show error message and date 1 should be
   d1 = Date3.AddDays(1).toString("d MMM yyyy");
   d3 = Date3.toString("d MMM yyyy");
}


if(Date4.AddDays(1)== Date2)
{ // validation true

   // store direct dropdown value because it is already in "d MMM yyyy" format
   d2 = ddlDate2.SelectedValue;
   d4 = ddlDate4.SelectedValue;

   // if dropdown is not in "d MMM yyyy" format
   d2 = Date2.toString("d MMM yyyy");
   d4 = Date4.toString("d MMM yyyy");
}
else
{
   // show error message and date 2 should be
   d2 = Date4.AddDays(1).toString("d MMM yyyy");
   d4 = Date4.toString("d MMM yyyy");
}
   

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