views:

141

answers:

2

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?

+1  A: 

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.

Joel Etherton
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?
Eric
there is a much easier way - see above answer. thanks anyways. +1
Eric
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.
Joel Etherton
+1  A: 

With a gridview named GridView1 some javascript code like:

document.getElementById('<%=GridView1.ClientID%>').style.fontSize = "12px";
Jan Jongboom
BEAST! Thanks, I appreciate it. I was a step away from this. I forgot the '.style'. thanks again.
Eric
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.
Joel Etherton
GridView doesn't do inline styling, etc. It's actually quite nice HTML it spits out; I'm pretty sure this works quite well.
Jan Jongboom