asp.net 日历控件出现在文本字段下方
我使用图像按钮来显示 asp.net 日历控件(该控件随 VS 2008 一起提供)。但是,当我单击图像按钮时,日历控件显示在应该填充的文本字段“下方”。如何让控件显示在文本字段的右侧?
我的代码是:
<asp:ImageButton ID="imgCalendar" runat="server" Height="17px"
ImageUrl="~/Images/CAL.gif"
onclick="imgCalendar_Click1" Width="19px"
Visible="true" ImageAlign="Middle" />
<asp:Panel ID="Panel1" runat="server">
<asp:Calendar ID="calStartDate" runat="server" BackColor="Transparent"
BorderColor="#FFCC66" BorderWidth="1px" DayHeaderStyle-BackColor="gainsboro"
DayNameFormat="Shortest" FirstDayOfWeek="Monday" Font-Bold="True"
Font-Names="Verdana" Font-Size="8pt" ForeColor="Gray" Height="102px"
OnSelectionChanged="calStartDate_SelectionChanged"
OtherMonthDayStyle-ForeColor="gray" SelectedDayStyle-BackColor="Navy"
SelectedDayStyle-Font-Bold="True" SelectorStyle-BackColor="gainsboro"
ShowGridLines="True" TitleStyle-BackColor="gray" TitleStyle-Font-Bold="True"
TitleStyle-Font-Size="12px" TodayDayStyle-BackColor="gainsboro" Visible="False" Width="62px">
<SelectedDayStyle BackColor="#404040" Font-Bold="True" />
<TodayDayStyle BackColor="#3A080B" ForeColor="White" />
<SelectorStyle BackColor="#FFCC66" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#3A080B" />
<DayHeaderStyle BackColor="#3A080B" Font-Bold="True" Height="1px" ForeColor="White" />
<TitleStyle BackColor="#E0C16B" Font-Bold="True" Font-Size="9pt" ForeColor="#3A080B" />
</asp:Calendar>
</asp:Panel>
I ma using an image button to display an asp.net calendar control (this control comes with VS 2008). However, when I click the image button, the calendar controls is displayed "below" the textfield that it is suppoed to populate. How can I get the control to appear on the right side of the textfield?
My code is:
<asp:ImageButton ID="imgCalendar" runat="server" Height="17px"
ImageUrl="~/Images/CAL.gif"
onclick="imgCalendar_Click1" Width="19px"
Visible="true" ImageAlign="Middle" />
<asp:Panel ID="Panel1" runat="server">
<asp:Calendar ID="calStartDate" runat="server" BackColor="Transparent"
BorderColor="#FFCC66" BorderWidth="1px" DayHeaderStyle-BackColor="gainsboro"
DayNameFormat="Shortest" FirstDayOfWeek="Monday" Font-Bold="True"
Font-Names="Verdana" Font-Size="8pt" ForeColor="Gray" Height="102px"
OnSelectionChanged="calStartDate_SelectionChanged"
OtherMonthDayStyle-ForeColor="gray" SelectedDayStyle-BackColor="Navy"
SelectedDayStyle-Font-Bold="True" SelectorStyle-BackColor="gainsboro"
ShowGridLines="True" TitleStyle-BackColor="gray" TitleStyle-Font-Bold="True"
TitleStyle-Font-Size="12px" TodayDayStyle-BackColor="gainsboro" Visible="False" Width="62px">
<SelectedDayStyle BackColor="#404040" Font-Bold="True" />
<TodayDayStyle BackColor="#3A080B" ForeColor="White" />
<SelectorStyle BackColor="#FFCC66" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#3A080B" />
<DayHeaderStyle BackColor="#3A080B" Font-Bold="True" Height="1px" ForeColor="White" />
<TitleStyle BackColor="#E0C16B" Font-Bold="True" Font-Size="9pt" ForeColor="#3A080B" />
</asp:Calendar>
</asp:Panel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我突然想到,我建议您设置
asp:Panel
的CssClass
属性并使用 CSS 定位它。控件生成的 HTML 可能会呈现块级元素(最有可能的是或
),这将导致它显示在新行上默认。
尝试使用
display: inline
或display: inline-block
或使用float
来定位它。根据您设置文本框样式的方式,您可能还需要修改其样式以适应日历的位置。
Off the top of my head, I'd suggest that you set the
CssClass
property of theasp:Panel
and position it using CSS. The HTML generated by the control likely renders block level elements (either<div>
or<table>
most likely) which will cause it to display on a new line by default.Try using
display: inline
ordisplay: inline-block
or usingfloat
to position it.Depending on the way you've styled your textbox, you may need to modify it's styles too to accommodate the positioning of the calendar.
将 style="float:right" 添加到文本框。
Add style="float:right" to the textbox.