Two tips for transforming the Asp.net calendar control to the pop-up date Selection Control and displaying long text fields in the gridview

Source: Internet
Author: User

Asp.net comes with a very good calendar control, but it still lacks the rendering method. Now we use a tip to easily create a pop-up date. Since then, you no longer have to go online to find the one with a lot of scripts.CodeThe JS-created pop-up date control.

 

The implementation method is simple: simply add JavaScript and some CSS to the page to create a simple pop-up date selector.

The. aspx code is as follows:

 

<Head id = "head1" runat = "server"> <br/> <title> No title page </title> <br/> <MCE: script Type = "text/JavaScript" Language = "JavaScript"> <! -- <Br/> function displaycalendar () <br/>{< br/> var datepicker = document. getelementbyid ("datepicker"); <br/> datepicker. style. display = 'block'; <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> <MCE: style type = "text/CSS"> <! -- <Br/> # datepicker <br/> {<br/> display: none; <br/> position: absolute; <br/> border: solid 2px black; <br/> background-color: White; <br/>}</P> <p> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> # datepicker <br/>{< br/> display: none; <br/> position: absolute; <br/> border: solid 2px black; <br/> background-color: white; <br/>}< br/> </style> <br/> </pead> <br/> <body> <br/> <Form ID = "form1" runat = "server"> <br/> <asp: label id = "label1" runat = "server" text = "Date:"> </ASP: Label> <br/> <asp: textbox id = "textbox1" runat = "server"> </ASP: textbox> <br/> <br/> <Div id =" datepicker "> <br/> <asp: calendar id = "calendar1" runat = "server" <br/> onselectionchanged = "calendar#selectionchanged"> </ASP: calendar> <br/> </div> <br/> <asp: button id = "button1" runat = "server" text = "button"/> <br/> </form> <br/> </body> <br/> </ HTML> <br/>

 

. Aspx. CS code:

 

Protected void calendar1_selectionchanged (Object sender, eventargs e) <br/>{< br/> textbox1.text = calendar1.selecteddate. tostring ("D"); <br/>}

 

Effect:

 

 

 

Tip 2:

When the gridview is used to present a lot of string records, and the width that can be set is very limited, we can use this technique of the tooltip attribute of the gridview. The tips are as follows:

Protected void gv_historyrecords_rowdatabound (Object sender, gridviewroweventargs e) <br/>{< br/> If (E. row. rowtype = datacontrolrowtype. datarow) <br/>{</P> <p> If (E. row. cells [2]. text. trim (). length> 7) <br/>{< br/> E. row. cells [2]. tooltip = E. row. cells [2]. text; <br/> E. row. cells [2]. TEXT = E. row. cells [2]. text. substring (0, 6) + "<B> .... </B> "; <br/>}< br/>}

 

It is mainly to first determine whether the character length of a field is greater than a set value. If it is greater than this value, the entire field value is saved to the tooltip attribute, then, extract the first number of characters and display them in the gridview.

Effect:

 

Of course, if you add some labels to The tooltip in the Code and set the display appearance, it will be more beautiful!

 

 

 

 

 

 

 

 

 

 

 

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.