目前可以简单的分为两种情况:
RadDatePicker控件用于选择时间,但是我们需要对选择的时间进行判断
第一种:两个时间均是在RadDatePicker控件中选择的。比如说:下订单时选择下订单的时间和付款的时间,条件是付款的日期是不能早于下订单的时间的,故作如下判断:
首先需要得到RadDatePicker控件所选中的值,顺便将时间的格式格式化成自己想要的格式
string orderDate=Convert.ToDateTime(rdpOrder.SelectedDate).ToString("yyyy-MM-dd");
string payDate=Convert.ToDateTime(rdpPay.SelectedDate).ToString("yyyy-MM-dd");
//将格式化好的时间进行解析
DateTime order=DateTime.Parse(orderDate);
DateTime pay=DateTime.Parse(payDate);
//在自己需要的地方进行判断
if(DateTime.Compare(pay,order)<0){
lblMessage.Text="付款日期不能早于下订单的日期";
}
第二种:选择一个RadDatePicker中的值,然后根据选择的这个时间对另外一个文本框赋值,比如说赋值为该日期的三天后
//同理,首先得到选中的值,然后给这个RadDatePicker控件添加监听事件,如果该控件中的值发生变化的话,就向服务器自动提交数据,当然提交数据的前提是将AutoPostBack属性设置为true;
protected void rdpOrder_SelectedDateChanged(object sender,Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e){
string orderDate=Convert.ToDateTime(rdpOrder.SelectedDate).ToString("yyyy-MM-dd");
DateTime payDate=Convert.ToDateTime(orderDate).AddDays(3);
string pay=Convert.ToDateTime(payDate).ToString("yyyy-MM-dd");
//将格式化好的时间赋值给另外一个文本框
txtBox.Text=pay;
}