动态日历选择 [英] Dynamic Calendar selection
本文介绍了动态日历选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本框,我想分别从两个日历控件中选择日期。现在我已将两个文本框的autopostback属性设置为true。但它没有发生。每当我从日历中选择一个日期时,它就不会反映在文本框中,直到发生回发为止。
以下是我的代码: -
Hi,
I have two textboxes in which I want to select dates from two calendar controls respectively. Now I have set the autopostback property of two textboxes to true. But it is not happening. Whenever I am selecting a date from the calendar, it is not reflecting in the textbox until a postback happens.
Below is my code:-
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class _Default : System.Web.UI.Page
{
string stdt;
string endt;
string conn;
protected void Page_Load(object sender, EventArgs e)
{
//txtfrmdt.Text = DateTime.Now.ToString();
//txttodt.Text = DateTime.Now.ToString();
if (!IsPostBack)
{
// string date2 = DateTime.Now.ToString();
// string str = date2.Trim();
//string date1 = str.Substring(0, 10);
//string date1 = DateTime.Now.ToShortDateString();
//DateTime dt = Convert.ToDateTime(date1);
Calendar2.SelectedDate = DateTime.Now;
// Session["connstring"] = Request.QueryString["testupload"].ToString();
}
BindCalender();
// bindgrid();
// DropDownList1.SelectedValue = Convert.ToString(Calendar1.SelectedDate);
// DropDownList1.SelectedItem.Text = Convert.ToString(Calendar1.SelectedDate);
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Calendar1.Visible = true;
// BindCalender();
}
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
Calendar2.Visible = true;
}
public void BindCalender()
{
//txtfrmdt.Text = Calendar1.SelectedDate.ToString();
//txttodt.Text = Calendar2.SelectedDate.ToString();
stdt = Calendar1.SelectedDate.ToString();
string s1 = stdt.Substring(0, 10);
txtfrmdt.Text = s1.ToString();
endt = Calendar2.SelectedDate.ToString();
string s2 = endt.Substring(0, 10);
txttodt.Text = s2.ToString();
Calendar1.Visible = false;
Calendar2.Visible = false;
//Response.Redirect("Default2.aspx");
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
// DropDownList1.Text = Convert.ToString(Calendar1.SelectedDate);
// DropDownList1.SelectedItem.Text = Convert.ToString(Calendar1.SelectedDate);
stdt = Calendar1.SelectedDate.ToString();
string s1 = stdt.Substring(0, 10);
txtfrmdt.Text = s1.ToString();
//Calendar1 .SelectedDate
}
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
endt = Calendar2.SelectedDate.ToString();
string s2 = endt.Substring(0, 10);
txttodt.Text = s2.ToString();
}
}
请帮助...
Please Help...
推荐答案
看看这个
http://bytes.com/topic/net/answers/481987-use-autopostback-vb-net [ ^ ]
这篇关于动态日历选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文