Some simple operations on the gridview in. net

Source: Internet
Author: User

1. When displaying datatime data in the gridview, remove the following time and minute seconds, for example, 00:00:00. Remove the following 00:00:00 operation method:

Add the property DataformatString = "{0: yyyy-MM-dd}" HtmlEncode = "false" to <asp: BoundField DataField = "birth" HeaderText = "Date of birth"/> ", the displayed date formats include 2008-01-01 and-12;
If DataformatString = "{0: d}" HtmlEncode = "false" is added, the displayed date formats include 2008-1-1 and-10.
If DataformatString = "{0: D}" HtmlEncode = "false" is added, the format of the displayed date is May 8, 1976, October 18, 1976,

HtmlEncode = "false" is essential!

 

2. In the text box, when displaying datatime data, remove the time, minute, and second method:

Rq. Text = Convert. ToDateTime (ds. Tables [0]. Rows [0] ["f_starttime"]. ToString (). to1_datestring ();

ToShortDateString (): This function belongs to the datatime data type. It is responsible for removing the hour, minute, and second.

 

3. When the mouse is in the gridview, the background color of each row changes. The operation is as follows:

Add the following statement to the RowDataBound event of the gridview:

If (e. Row. RowType = DataControlRowType. DataRow)
{
// Change the background color when the mouse stays
E. Row. Attributes. Add ("onmouseover", "c = this. style. backgroundColor; this. style. backgroundColor = '# ffccff '");
// Restore the background color when you move the mouse away.
E. Row. Attributes. Add ("onmouseout", "this. style. backgroundColor = c ");
}

In this way, the effect can be achieved.


From the whx_1113 Column

Related Article

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.