473,396 Members | 1,590 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,396 software developers and data experts.

Assigning Styles Dinamycally to a data grid!

jullianps
HI everyone, here is my question and I hope it isn't or it hasn't been posted before, probably it has but I spent a few minutes looking through the forums and with the search feature and nothing could solve or help me with my problem so here I go.

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...


<% While ((Repeat1__numRows <> 0) AND (NOT rs_selecciona_prestamos.EOF)) %>
<tr>
<td class="style6"><div align="center"><a href="registro_actividad_edita.asp?loan_id=<%=rs_s elecciona_prestamos("id_file")%>"><img src="images/edit_loan.gif" width="22" height="23" border="0" /></a></div></td>
<td class="style6"><div align="center"><a href="registro_actividad_log.asp?loan_id=<%=rs_sel ecciona_prestamos("id_file")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
<td class="Call CambiaEstilos()"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("last_name").Value)%><%=(rs_selecciona_presta mos.Fields.Item("name").Value)%></div></td>
<td class="return CambiaEstilos()"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("address").Value)%></div></td>
<td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("PRCO").Value)%></div></td>
<td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("PSI").Value)%></div></td>
<td class="style6"><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Ite m("loan_amount").Value), 2, -2, -2, -2) %></div></td>
<td class="style6"><div align="center"><%= FormatCurrency((rs_selecciona_prestamos.Fields.Ite m("earning").Value), 2, -2, -2, -2) %></div></td>
<td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("lender").Value)%></div></td>
<td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("closing_date").Value)%></div></td>
<td class="style6"><div align="center"><%=(rs_selecciona_prestamos.Fields. Item("loan_status").Value)%></div></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rs_selecciona_prestamos.MoveNext()
Wend
%>




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.
Feb 29 '08 #1
3 1412
jeffstl
432 Expert 256MB
You have to use the OnItemDataBound method.

When a datagrid is populated one of its properties is a OnItemDataBound which executes for each row "written"

Within this event you can check conditions for coloring rows, cells, etc.

So within your datagrid properties have something like this:

Expand|Select|Wrap|Line Numbers
  1.  OnItemDataBound="DataGrid1_ItemDataBound"
  2.  
Then in your code behind you will have a

Expand|Select|Wrap|Line Numbers
  1. Private Sub DataGrid1_ItemDataBound(source As Object, e As DataGridItemEventArgs)
  2.  
  3.      'My code
  4.      if MyCondition = "Yes" then
  5.           e.Item.Cells(1).BackColor = System.Drawing.Color.Blue
  6.      end if
  7.  
  8.  
  9. End Sub
  10.  
  11.  
Make sure you have declared the namespace for the colors too
<%@ import Namespace="System.Drawing" %>
Mar 7 '08 #2
jeffstl
432 Expert 256MB
Woah...

Im sorry, I guess I should have looked at your code.

When you said datagrid I automatically assumed you were using .NET

It appears you are using classic asp? Can you re-post your code using the [code] tags? It would make it a whole lot easier to read I think.
Mar 7 '08 #3
DrBunchman
979 Expert 512MB
This thread was posted twice by the OP:

http://www.thescripts.com/forum/thre...ml#post3101105

Dr B
Mar 7 '08 #4

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

Similar topics

0
by: Rob | last post by:
I need to create a custom data grid that has its rows colored with different background colors to denote each record status. For example rows that represent order are due in 2 hours have yellow...
8
by: Woody Splawn | last post by:
Lets say I have a winform that is populated with a dataset. The dataset and data table may have several rows in it. Lets say I am looking at the winform and I want to assign a value to a certain...
3
by: Richard | last post by:
Rather than all that painting, brush, etc. code to change the styles of a ..NET datagrid to start with and on the fly, I'd rather be able to set a lot of the stuff in the designer properties of the...
8
by: Viken Karaguesian | last post by:
Hello all, I'll start with this question: Can I assign an ID *and* a CLASS to a DIV? I am under the impression that you can. I'm having a problem that I can't seem to figure out. Some...
1
by: Michael | last post by:
I am using Visual Studio 2005 (ASP 2.0) to build a webpage that uses a Microsoft Access Database. The data in the database simply holds the information on a link to a document that I am storing on...
4
by: Peter | last post by:
I am using ArrayDataView from the following link, my question is how do I apply column styles to this DataGrid that uses ArrayDataView instead of DataSet ...
3
by: Peter | last post by:
I am using ArrayDataView from the following link, my question is how do I apply column styles to this DataGrid that uses ArrayDataView instead of DataSet ...
3
by: Charles Law | last post by:
This is driving me mad. Can someone please put me out of my misery? I have a DataSet which I wish to use as the data source for a grid control (it is actually an Infragistics grid). When I assign...
0
by: chithrausha | last post by:
hi can anyone help me in setting the styles for a grid control. i want a design like this. iam having a grid control in which i want to display different styles for header text and different...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.