473,378 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Assign CSS Style to a Data Grid Row

jullianps
I have an ASP page where I have a "Repeat region" which is populated dinamycally from a Database, everything works perfectly, the thing is that I thought it would be cool to fill a row or to set its background color (for that single row) if the value of one of the fields = something in particular, and I've tried making a function that changes the style through VBscript and Java Script then trying to call the function each time or on every single line on the repeat region with no luck so far, of course I am doing something wrong so please any help is appreciated.

Here is an example of the repeat region that I have:

Note that the third and fourth recordset results have on their "class" tag an attempt to call either a JavaScript or a VBscript function, again, with no luck...

Expand|Select|Wrap|Line Numbers
  1. <% While ((Repeat1__numRows <> 0) AND (NOT rs_selecciona_prestamos.EOF)) %>
  2. <tr>
  3. <td class="style6"><div align="center"><a href="registro_actividad_edita.asp?loan_id=<%=rs_selecciona_prestamos("id_file")%>"><img src="images/edit_loan.gif" width="22" height="23" border="0" /></a></div></td>
  4. <td class="style6"><div align="center"><a href="registro_actividad_log.asp?loan_id=<%=rs_selecciona_prestamos("id_file")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
  5. <td class="Call CambiaEstilos()"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("last_name").Value)%><%=(rs_selecciona_prestamos.Fields.Item("name").Value)%></div></td>
  6. <td class="return CambiaEstilos()"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("address").Value)%></div></td>
  7. <td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("PRCO").Value)%></div></td>
  8. <td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("PSI").Value)%></div></td>
  9. <td class="style6"><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Ite m("loan_amount").Value), 2, -2, -2, -2) %></div></td>
  10. <td class="style6"><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Ite m("earning").Value), 2, -2, -2, -2) %></div></td>
  11. <td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("lender").Value)%></div></td>
  12. <td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("closing_date").Value)%></div></td>
  13. <td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("loan_status").Value)%></div></td>
  14. </tr>
  15. <% 
  16. Repeat1__index=Repeat1__index+1
  17. Repeat1__numRows=Repeat1__numRows-1
  18. rs_selecciona_prestamos.MoveNext()
  19. Wend
  20. %>
  21.  


It is not event worth it for me to post the functions Ive been using since they are really guessings on how to do it, but probably you already got the idea and if there is something missing please let me know so I can edit the this text and clarify some doubts if that helps you to give me a hand....


Thanks
Marco



Probably I am not even doing in the right way, it must be a way to do it so I hope to get any leads or tips.
Mar 3 '08 #1
4 1897
DrBunchman
979 Expert 512MB
Hi Marco,

You can change the class of something dynamically by testing for your condition before outputting that row and setting a variable which holds the name of the class to use. Like so:

Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. 'Test to see if you want to change the background colour
  3. If rs("Something") = SomethingElse Then
  4. sClass = "style6"
  5. Else
  6. sClass = "style7"
  7. End If
  8. %>
  9.  
  10. <!-- Then display the table row with the appropriate class -->
  11. <tr class="<%=sClass%>">
  12.  
I've done this for the table row but you can do it for table data or anything you like.

Let me know if this helps,

Dr B
Mar 3 '08 #2
Hi Marco,

You can change the class of something dynamically by testing for your condition before outputting that row and setting a variable which holds the name of the class to use. Like so:

Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. 'Test to see if you want to change the background colour
  3. If rs("Something") = SomethingElse Then
  4. sClass = "style6"
  5. Else
  6. sClass = "style7"
  7. End If
  8. %>
  9.  
  10. <!-- Then display the table row with the appropriate class -->
  11. <tr class="<%=sClass%>">
  12.  
I've done this for the table row but you can do it for table data or anything you like.

Let me know if this helps,

Dr B


First of anything thanks for the response, I tried your suggestion and looks like it might be the solution to my problem, I did exactly what you suggested but apparently I am doing something wrong, the code looks ok but at the same time it is not working well, look at the code please and on the IF statement the decision always go to the last ELSE as if the other 2 comparisons were not succesful when indeed there are values that should make those statements valid, What am I doing wrong ? I really appreciate the help on this!


Expand|Select|Wrap|Line Numbers
  1.  
  2.         <% While ((Repeat1__numRows <> 0) AND (NOT rs_selecciona_prestamos.EOF)) %>
  3.                     <% 
  4.                     dim sClass
  5.                     'Test to see if you want to change the background colour
  6.                     If (rs_selecciona_prestamos.Fields.Item("loan_status").Value) = "Withdrawn" Then
  7.                         sClass = "DeniedWithdrawn"
  8.                     Elseif (rs_selecciona_prestamos.Fields.Item("loan_status").Value) = "Processing" Then
  9.                         sClass = "style4"
  10.                     Else 
  11.                         sClass = "style1"
  12.                     End If
  13.                     %>
  14.  
  15.                         <tr class="<%=sClass%>">
  16.                             <td class="Style6"><div align="center"><a href="registro_actividad_edita.asp?loan_id=<%=rs_selecciona_prestamos("id_file")%>"><img src="images/edit_loan.gif" width="22" height="23" border="0" /></a></div></td>
  17.                             <td class="Style6"><div align="center"><a href="registro_actividad_log.asp?loan_id=<%=rs_selecciona_prestamos("id_file")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
  18.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("last_name").Value)%><%=(rs_selecciona_prestamos.Fields.Item("name").Value)%></div></td>
  19.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("address").Value)%></div></td>
  20.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("PRCO").Value)%></div></td>
  21.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("PSI").Value)%></div></td>
  22.                             <td class="Style6"><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Item("loan_amount").Value), 2, -2, -2, -2) %></div></td>
  23.                             <td class="Style6"><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Item("earning").Value), 2, -2, -2, -2) %></div></td>
  24.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("lender").Value)%></div></td>
  25.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("closing_date").Value)%></div></td>
  26.                             <td class="Style6"><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("loan_status").Value)%></div></td>
  27.                           </tr>
  28.                          <% 
  29.                         Repeat1__index=Repeat1__index+1
  30.                         Repeat1__numRows=Repeat1__numRows-1
  31.                         rs_selecciona_prestamos.MoveNext()
  32.                 Wend
  33.                 %> 
  34.  
  35.  
Thanks!
Marco
Mar 5 '08 #3
ok ok, I found what my problem was and actually it was within the values of the fields inside the Data Base but the code ended like this

Expand|Select|Wrap|Line Numbers
  1.  
  2. <% While ((Repeat1__numRows <> 0) AND (NOT rs_selecciona_prestamos.EOF)) %>
  3.                        <% 
  4.                     dim sClass,valorcampo
  5.                     'Test to see if you want to change the background colour
  6.                     valorcampo=(rs_selecciona_prestamos.Fields.Item("loan_status").Value)
  7.                     'response.write(valorcampo)
  8.                     If valorcampo = "Prospect" Then
  9.                         sClass = "Prospect"
  10.                         'response.Write(sClass)
  11.                     Elseif valorcampo = "Processing" Then
  12.                         sClass = "Processing"
  13.                         'response.Write(sClass)
  14.                     Elseif valorcampo = "Closed" or valorcampo = "Funded" Then
  15.                         sClass = "CloseFunded"
  16.                     Elseif valorcampo = "Denied" or valorcampo = "Withdrawn" Then
  17.                         sClass = "DeniedWithdrawn"
  18.                     End If
  19.                     %>
  20.                         <tr class="<%=sClass%>">
  21.                             <td><div align="center"><a href="registro_actividad_edita.asp?loan_id=<%=rs_selecciona_prestamos("id_file")%>"><img src="images/edit_loan.gif" width="22" height="23" border="0" /></a></div></td>
  22.                             <td><div align="center"><a href="registro_actividad_log.asp?loan_id=<%=rs_selecciona_prestamos("id_file")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
  23.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("last_name").Value)%><%=(rs_selecciona_prestamos.Fields.Item("name").Value)%></div></td>
  24.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("address").Value)%></div></td>
  25.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("PRCO").Value)%></div></td>
  26.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("PSI").Value)%></div></td>
  27.                             <td><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Item("loan_amount").Value), 2, -2, -2, -2) %></div></td>
  28.                             <td><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Item("earning").Value), 2, -2, -2, -2) %></div></td>
  29.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("lender").Value)%></div></td>
  30.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("closing_date").Value)%></div></td>
  31.                             <td><div align="center"><%=(rs_selecciona_prestamos.Fields.Item("loan_status").Value)%></div></td>
  32.                           </tr>
  33.                          <% 
  34.                         Repeat1__index=Repeat1__index+1
  35.                         Repeat1__numRows=Repeat1__numRows-1
  36.                         rs_selecciona_prestamos.MoveNext()
  37.                 Wend
  38.                 %> 
  39.  
  40.  

THANKS FOR THE GREAT HELP
Marco
Mar 5 '08 #4
DrBunchman
979 Expert 512MB
No problem Marco, glad you got it sorted.

Dr B
Mar 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bhom | last post by:
I am trying to create a grid on a form that looks like the 'Split Transaction' grid in Quicken - it allows drop down controls in various cells of grid to make a selection, and then stores the text...
2
by: Jordan O'Hare | last post by:
Hello Everyone, I am after some help with the following: I have a windows application that contains a list box and two data grids. All three controls are binded to a dataset that contains...
2
by: Tonya | last post by:
Hi, i wanted to know how i could resolve the following error message: An unhandled exception of type 'System.ArgumentException' occurred in system.dll Additional information: The data grid...
6
by: Tim Cartwright | last post by:
I am trying to figure out how to change the gridview caption style, but I can not figure out how. I added table caption { background-color: #5D7B9D; color: White; font-size: 16pt; } to my...
3
by: Daniel | last post by:
Hi all. Help! What am I doing wrong? My datagrid works fine, the columns are created and the data is filled. However, I just cannot resize the column widths to what I want them to be. I...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
1
by: Ryan Liu | last post by:
Hi, Is there a way to specify data Grid column Style if its DataSource is an IList(ArrayList), not a datatable? Can I selectively only show few columns, not all of its properties? Thanks!
4
by: mike | last post by:
how can I change the font color for an alternating row where the column data is formatted as a link? setting a style in the stylesheet for a { color:white; }
0
by: =?Utf-8?B?YWxleF9jYXJvMQ==?= | last post by:
Hi, I would like to use a multibinding to determine the fill value of my rectangle style. <Style x:Key="StyleRect" TargetType="{x:Type Rectangle}"> <Setter Property="Fill"> <Setter.Value>...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.