0

I want to change the font size of my gridview in javascript because i am creating a printable version. How can I change the font size in javascript for the gridview?

2 Answers 2

1

With a gridview named GridView1 some javascript code like:

document.getElementById('<%=GridView1.ClientID%>').style.fontSize = "12px";
Sign up to request clarification or add additional context in comments.

4 Comments

BEAST! Thanks, I appreciate it. I was a step away from this. I forgot the '.style'. thanks again.
This assumes that no styling is applied to individual elements within the Gridview. It will also not affect buttons/dropdownlists/links or any other element that has a class already specifically applied to it.
GridView doesn't do inline styling, etc. It's actually quite nice HTML it spits out; I'm pretty sure this works quite well.
What about if I want to change AllowPaging attribute to true?
1

There are a lot of ways to do it, but the method I would use if I were to attempt it is to get the unique ClientID of each control (label, TextBox, literal) in the gridview that I wanted to change and as it was going through the RowCreated event, I would inject the ClientID into an array of control names. Then when the action in JavaScript is executed, I'd simply need to traverse the array and set the style for each control. Using jQuery would even speed this up.

3 Comments

it would seem as though there is an easier way to go about this. I understand the attributes of the Grid are server side but there must be an easier way right?
there is a much easier way - see above answer. thanks anyways. +1
It depends on the level you want to go to. If your Gridview is nothing but text, then the solution from @Jan would work marvelously. But if you have any custom elements or specifically styled pieces, they won't be impacted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.