We help IT Professionals succeed at work.

using fixed header datagrid  in masterpage

jaws1021 asked
Last Modified: 2012-06-27
If I use master page and I want to fixed the header in my datagrid , where can I put this code
<style type="text/css"> <!-- .DataGridFixedHeader {background-color: white; position:relative; top:expression(this.offsetParent.scrollTop);} --> </style>
before master page, I was putting this code to head of the html , how this will be with master page? Also, is it possible to use same code for gridview instead datagrid?
Watch Question

In any case, I would recommend putting that in a seperate .css file that can be used in the MasterPage by using the link tag.
If you want to do it in the MasterPage without using a seperate style sheet, the yes, the simplest way is to just put it in the header of the MasterPage.
Noe that part can be done programmatically from the page itself using something like the following:
Literal ltrScript = new Literal();
ltr.Text = "<script type='text/javascript'>doSomething();</script>";


am I going to put that code in css file in body part? or where
<link type='text/css' rel='stylesheet' ref='myStyleSheet.css'>
you can put that in the head of the master page


okay what would be my stylesheet has
<style type="text/css"> <!-- .DataGridFixedHeader {background-color: white; position:relative; top:expression(this.offsetParent.scrollTop);} --> </style>

top is not working like that in my style sheet.

I created my stylesheet like that my not working this way
I am very very confused now..even though it is very simple thing I know..
      background-color: white;
        what to put here?


and I don't want to put on master page head part because I will not be using that in every page
The problem is the expression.
It is specific to IE and does not work in a seperate .css file. Also this approach is not standard. If you want to still use expression, you cannot put your style in a seperate style sheet. You can use the code I provided to put your style in the head of the masterpage.
By using my code, it will only be added to the pages that contain that code.


let me try to explain better,
I have this code in head part of my regular form, and was working just fine.
<style type="text/css"> <!-- .DataGridFixedHeader {background-color: white; position:relative; top:expression(this.offsetParent.scrollTop);} --> </style>
BUT, now I already have Master Page created before, I added a new item gets from Master Page right, that time, when I clicked on source , all I see masterpage stuff and aspcontent thing, no head, body html, right, that made me confused, NOW i don't know where to place that code above. I don't want to place on master page because master page doesn't want that on it, don't need fixed header thing for the master page.
Then I created css file, but top property is not working fine.. I am stuck.
I hope this makes more sense..
This one is on us!
(Get your first solution completely free - no credit card required)


Okay, but I use vb.net2005, how to do on that?
Dim ltrScript As new Literal()
ltr.Text = "<style type='text/css'> <!-- .DataGridFixedHeader {background-color: white; position:relative; top:expression(this.offsetParent.scrollTop);} --> </style>";

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.