Use CSS to fix the top and left table headers in the gridview (similar to the Excel worksheet) (ie Only)

Source: Internet
Author: User

Take the effect of setting through CSS in the previous article and copying it to a window similar to excel (fix the above and left-side table headers)

This time, I want to apply the same effect to ASP. NET. However, if you have encountered several problems in the middle, you need to exclude them one by one. Remember the following method:

1. first, this method is not the standard CSS coding method. However, when a webform is opened, aspx will add a line to check whether it is in the standard format, this line will cause loss, and this line must be deleted

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

2. In the HTML generated by the gridview, a div is automatically added, which causes this. parentelement. offsetparent. parentelement. scrollleft In the CSS.

Take the token and modify it

This. parentelement. offsetparent. offsetparent. scrollleft

 

For example:

First, add CSS settings to the same table.

.FixedTitleRow   {       position: relative;        table-layout:fixed;    top: expression(this.offsetParent.scrollTop-2);    background-color:White;    z-index: 10;   }   .FixedTitleRow th{    text-overflow:ellipsis;    overflow:hidden;    white-space: nowrap;    padding:2px;}   .FixedTitleColumn   {       position: relative;        left: expression(this.parentElement.offsetParent.scrollLeft-2);   }      .FixedDataColumn   {       position: relative;       left: expression(this.parentElement.offsetParent.offsetParent.scrollLeft-2);   } 

Then add the aspx upload case and remember to remove it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The content of the gridview is as follows:

<Div style = "width: 600px; Height: 400px; overflow: Scroll; Z-index: 100;"> <asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false" datakeynames = "orderid" performanceid = "sqlperformance1" emptydatatext = "No information is displayed. "Cellpadding =" 4 "forecolor =" #333333 "gridlines =" NONE "> <rowstyle backcolor =" # e3eaeb "/> <columns> <asp: boundfield datafield = "orderid" headertext = "orderid" readonly = "true" sortexpression = "orderid"> 

The result is as follows:

Easy to use

  1. Set cssclass = fixedtitlecolumn of headstyle and cssclass = fixeddatacolumn of itemstyle in the left-side data row.
  2. Set cssclass = fixedtitlerow for the headstyle of the entire gridview.

This is done !!

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.