Asp.net time control usage

Source: Internet
Author: User

For the JS files to be used, visit http://d.download.csdn.net/down/2387457/taomanto download them for free;

 

The following describes how to use it:

Step 1:

Download the JS file from the address provided by me and decompress it to a directory of the project.

 

Step 2:

Add the wdatepicker. js file in the JS file to the ASPX page that requires the time control.

For example, <SCRIPT src = "../JS/my97datepicker/wdatepicker. js" type = "text/JavaScript"> </SCRIPT>

Add two text boxes. The time control is transformed by textbox. The Code is as follows:

<Asp: Panel id = "Panel1" style = "width: 100%" runat = "server">

Start time <input id = "tbstarttime" type = "text" runat = "server" style = "width: 102px"/>

End Time <input id = "tbendtime" type = "text" runat = "server" style = "width: 102px"/>
<Asp: button id = "btnquery" runat = "server" text = "query" onclick = "btnquery_click"/>

</ASP: Panel>

 

 

Step 3:

Add the following code to the background Aspx. CS file:

 

Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Adddatecontrol ();
Tbstarttime. value = datetime. Now. tostring ("yyyy-mm-dd ");
Tbendtime. value = datetime. Now. tostring ("yyyy-mm-dd ");
}
}

 

/// <Summary>
/// Set the date input box
/// </Summary>
Private void adddatecontrol ()
{
Tbstarttime. Attributes. Add ("class", "wdate ");
Tbstarttime. Attributes. Add ("onfocus", "New wdatepicker (this, '% Y-% m-% d', false )");
Tbendtime. Attributes. Add ("class", "wdate ");
Tbendtime. Attributes. Add ("onfocus", "New wdatepicker (this, '% Y-% m-% d', false )");
}

 

The above is the change to the text box style, this is the text box you see will be a datetimepicker, the effect is good, click the link below to view the effect: http://hi.csdn.net/space-95339-do-album-picid-551501.html

Next, you may be most concerned about how to obtain the time value. In fact, it is also very simple, as long as the value is as follows:

Datetime dtstart = datetime. parseexact (tbstarttime. value, "yyyy-mm-dd", system. Globalization. cultureinfo. currentculture );

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.