format grid column (all of them)

G

Guest

I've seen stuff on changing row colors based on something, i've seen how to
create columns on the fly, how can I change an color of the entire column
based on certain criteria?

I need to change the color (highlight) an entire column(s) of my grids based
on what the user selected in the drop down
 
K

Karl

If you give your rows a unique id it's pretty easy

<select onSelectIndexChange="HighLightRow(this)"><option....>...</select>
<table>
<tr id="1">
<td></td>
<td></td>
</tr>
<tr id="2">
<td></td>
<td></td>
</tr>
<tr id="3">
<td></td>
<td></td>
</tr>
</table>


notice they don't have a runat="Server"....they are just client-side Ids..

<script language="javascript">
function HighLightRow(sel){
var tr = null;
switch (sel.options[sel.selectedIndex].value){
case "1":
tr = document.getElementsById("1");
break;
case "blah";
tr = document.getElementsById("2");
break;
}
var tds = td.getElementsByTagName("td");
for (var i = 0; i < tds.length; ++i){
tds.className = 'highlightedClass';
}
}
</script>

something like that ought to work.
 
K

Karl

Yes, I know..it won't matter...when it gets rendered to the client it's all
just normal html...I was just making sure you didn't put a runat="server" in
there..

As long as you can get a unique id="xxx" in each <tr>, you'll be set.

Karl
 
G

Guest

I can't put a unique id on it the tables due to 1 only have 3 grids and each
one displays different data per selection.
Example:

Grid 1 displays everything on cars
it also displays everything on trucks
different headers and different dataitems

grid 2 shows everythng on boats
cruisers, yachts, etc
again, dffierent headers (some are added and removed)
and different data items

etc
 
G

Guest

I figured it out and i didn't use the javascript.

this does it

dgCars.Columns(4).ItemStyle.BackColor = System.Drawing.Color.yellow
 
L

Laiju Skaria

Hello

u can do the following in ur ItemCreated event

If e.Item.ItemType = "ur required type"
If (check ur condition here)
e.Item.BackColor = System.Drawing.Color.Aqua;

else

gridItem.BackColor = System.Drawing.Color.Azure ;



here e is the DataItem that u'll receive as parameter in that event.....



hope this will help u



smiles,

Laiju





IGotYourDotNet said:
I don't think this will work since all the rows in my datagrid are databound
(form runat=server>

is not a regular html table until runtime. I
I'll give it a shot though and see what happens

Karl said:
If you give your rows a unique id it's pretty easy

<select
onSelectIndexChange="HighLightRow(this)"> said:
<table>
<tr id="1">
<td></td>
<td></td>
</tr>
<tr id="2">
<td></td>
<td></td>
</tr>
<tr id="3">
<td></td>
<td></td>
</tr>
</table>


notice they don't have a runat="Server"....they are just client-side Ids..

<script language="javascript">
function HighLightRow(sel){
var tr = null;
switch (sel.options[sel.selectedIndex].value){
case "1":
tr = document.getElementsById("1");
break;
case "blah";
tr = document.getElementsById("2");
break;
}
var tds = td.getElementsByTagName("td");
for (var i = 0; i < tds.length; ++i){
tds.className = 'highlightedClass';
}
}
</script>

something like that ought to work.


I've seen stuff on changing row colors based on something, i've seen
how
to
create columns on the fly, how can I change an color of the entire column
based on certain criteria?

I need to change the color (highlight) an entire column(s) of my grids based
on what the user selected in the drop down
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top