简体   繁体   English

如何将按钮重定向到日历属性,并在vb.net中用所选日期填充文本框?

[英]how to redirect a button to calendar properties and fill the text box with the selected date in vb.net?

在此处输入图片说明

Hello i really need your help regarding the image as attached. 您好,我真的需要您提供有关图像的帮助。 I'm using vb.net. 我正在使用vb.net。 I want to do something like the image. 我想做类似图像的事情。 The first step is user will click the button after that, the Calendar will visible and user will pick the date and date will fill in the text box. 第一步是用户单击该按钮,然后日历将可见,用户将选择日期,日期将填充在文本框中。 I dont want to use the basic date picker. 我不想使用基本的日期选择器。

What should i fill inside this code ? 我应该在这段代码中填写什么?

Protected Sub Calendar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCalendar.Click

End Sub

I recommend the ASP.NET AJAX Toolkit Calendar Extender . 我建议使用ASP.NET AJAX工具包日历扩展程序

You can use it like this: 您可以像这样使用它:

Markup: 标记:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>
<asp:ImageButton ID="imgPopup" ImageUrl="images/calendar.png" 
                 ImageAlign="Bottom" runat="server" />
<cc1:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" 
                      TargetControlID="txtDate" Format="dd/MM/yyyy">
</cc1:CalendarExtender>

As you can see the CalendarExtender simply wants to know what server control ( txtDate text box in this case) to use as the display of the date selected from the calendar control and what button ( imgPopup image button in this case) triggers the popup of the calendar. 如您所见, CalendarExtender只是想知道要使用哪个服务器控件(在这种情况下为txtDate文本框)显示从日历控件中选择的日期,以及哪个按钮(在这种情况下为imgPopup图像按钮)触发弹出式窗口。日历。 You can also control the format of the date. 您还可以控制日期的格式。 Beyond that the extender control does the rest. 除此之外,扩展器控件还可以完成其余工作。

Note: In this example, the text box is made read-only, thus forcing the user to click the calendar popup to select a date. 注意:在此示例中,文本框被设置为只读,从而迫使用户单击日历弹出窗口以选择日期。 This may or may not fit your needs; 这可能会或可能不会满足您的需求; so if you want the user to be able to type directly into the text box, then remove the ReadOnly="true" attribute from the text box control. 因此,如果您希望用户能够直接在文本框中键入内容,请从文本框控件中删除ReadOnly="true"属性。

Put a Calendar control on your form. 将日历控件放在窗体上。 Also a button, and text box. 还有一个按钮和文本框。 This code will make the calendar appear when the button is pressed. 按下按钮后,此代码将使日历出现。 When the calendar date is chosen, the calendar will disappear and put the date in the text box. 选择日历日期后,日历将消失,并将日期放入文本框中。

Protected Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs) Handles Calendar1.SelectionChanged
    TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()
    Calendar1.Visible = False
End Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Calendar1.Visible = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM