首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

新手弱问:怎么在页面上实现 探出的选择日期效果呢

2012-02-01 
新手弱问:如何在页面上实现 探出的选择日期效果呢?RT[解决办法]给你两个例子:第一个:table cellpadding

新手弱问:如何在页面上实现 探出的选择日期效果呢?
RT

[解决办法]
给你两个例子:

第一个:

<table cellpadding= "0 " cellspacing= "0 ">
<tr>
<td>
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox> </td>
</tr>
<tr>
<td style= "height: 19px ">
<asp:Calendar ID= "Calendar1 " runat= "server " OnSelectionChanged= "Calendar1_SelectionChanged ">
</asp:Calendar>
</td>
</tr>
</table>

protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Attributes[ "onclick "] = "var x= " + this.Calendar1.ClientID +
";x.style.display=x.style.display== 'inline '? 'none ': 'inline '; ";
this.Calendar1.Style[ "position "] = "absolute ";
this.Calendar1.Style[ "display "] = "none ";
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.Calendar1.SelectedDate.Date.ToString( "D ");
}


例子二:
<table cellpadding= "0 " cellspacing= "0 ">
<tr>
<td>
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox> </td>
</tr>
<tr>
<td style= "height: 19px ">
<asp:Calendar ID= "Calendar1 " runat= "server " OnSelectionChanged= "Calendar1_SelectionChanged "
OnVisibleMonthChanged= "Calendar1_VisibleMonthChanged "> </asp:Calendar>
</td>
</tr>
</table>

public partial class _Default : System.Web.UI.Page,IPostBackEventHandler
{

protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Attributes[ "onclick "] = this.ClientScript.GetPostBackEventReference(this, " ");
this.Calendar1.Style[ "position "] = "absolute ";
if (!IsPostBack)
this.Calendar1.Visible = false;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.Calendar1.SelectedDate.Date.ToString( "D ");
this.Calendar1.Visible = false;
}

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
this.Calendar1.VisibleDate = e.NewDate;
}

#region IPostBackEventHandler 成员

public void RaisePostBackEvent(string eventArgument)
{
this.Calendar1.Visible = true;
}

#endregion
}

热点排行