如何通过一个时间控件例如Calendar1选择的时间来显示本页面的内容页面代码如下
publicpartialclassinclude_Default2:System.Web.UI.Page{protectedvoidPage_Load(objectse...
public partial class include_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int nResult = -1;
if (!Page.IsPostBack)
{
this.Calendar1.SelectedDate = DateTime.Now;
//this.TextBox1.Text = TextBox1.Text.ToString();
if (Request.Params["cdate"] != null)
{
if (Int32.TryParse(Request.Params["cdate"].ToString(), out nResult) == false) { return; }
SqlDataReader dr = Getnews(Int32.Parse(Request.Params["cdate"].ToString()));
if (dr.Read())
{
Label1.Text = dr["text"].ToString();
}
}
}
}
public SqlDataReader Getnews(int date)
{
string cdate = this.Calendar1.SelectedDate.ToShortDateString();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTION"].ConnectionString);
string cmdText = "SELECT * FROM sell WHERE cdate="+date;
SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
SqlDataReader dr = null;
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime dt = Calendar1.SelectedDate;
DataSet ds = new DataSet();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTION"].ConnectionString);
myConnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select text from sell where cdate = '" + dt.ToString("yyyy-MM-DD") + "'";
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
//Label1.Text == "";
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
Label1.Text += dr.ToString() + "<br/>";
}
}
else
{
Label1.Text = "今天会场空置!";
}
myConnection.Close();
cmd.Dispose();
sda.Dispose();
ds.Dispose();
}
} 展开
{
protected void Page_Load(object sender, EventArgs e)
{
int nResult = -1;
if (!Page.IsPostBack)
{
this.Calendar1.SelectedDate = DateTime.Now;
//this.TextBox1.Text = TextBox1.Text.ToString();
if (Request.Params["cdate"] != null)
{
if (Int32.TryParse(Request.Params["cdate"].ToString(), out nResult) == false) { return; }
SqlDataReader dr = Getnews(Int32.Parse(Request.Params["cdate"].ToString()));
if (dr.Read())
{
Label1.Text = dr["text"].ToString();
}
}
}
}
public SqlDataReader Getnews(int date)
{
string cdate = this.Calendar1.SelectedDate.ToShortDateString();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTION"].ConnectionString);
string cmdText = "SELECT * FROM sell WHERE cdate="+date;
SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
SqlDataReader dr = null;
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime dt = Calendar1.SelectedDate;
DataSet ds = new DataSet();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTION"].ConnectionString);
myConnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select text from sell where cdate = '" + dt.ToString("yyyy-MM-DD") + "'";
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
//Label1.Text == "";
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
Label1.Text += dr.ToString() + "<br/>";
}
}
else
{
Label1.Text = "今天会场空置!";
}
myConnection.Close();
cmd.Dispose();
sda.Dispose();
ds.Dispose();
}
} 展开
2个回答
展开全部
_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Now.Date)
{
e.Day.IsSelectable = false;
}
}
{
if (e.Day.Date < DateTime.Now.Date)
{
e.Day.IsSelectable = false;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接调用方法名就可以了啊
更多追问追答
追问
请问是否可以帮我完成这段代码,谢谢。
追答
你创建个时间对象,然后设定一下时间,在把方法名弄在里面就行了啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询