Assign CSS Style to a Data Grid Row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jullianps
    New Member
    • Feb 2008
    • 7

    Assign CSS Style to a Data Grid Row

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

    [code=asp]
    <% While ((Repeat1__numR ows <> 0) AND (NOT rs_selecciona_p restamos.EOF)) %>
    <tr>
    <td class="style6"> <div align="center"> <a href="registro_ actividad_edita .asp?loan_id=<% =rs_selecciona_ prestamos("id_f ile")%>"><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.a sp?loan_id=<%=r s_selecciona_pr estamos("id_fil e")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
    <td class="Call CambiaEstilos() "><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("last _name").Value)% ><%=(rs_selecci ona_prestamos.F ields.Item("nam e").Value)%> </div></td>
    <td class="return CambiaEstilos() "><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("addr ess").Value)%> </div></td>
    <td class="style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("PRCO ").Value)%> </div></td>
    <td class="style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("PSI" ).Value)%></div></td>
    <td class="style6"> <div align="center"> <%= FormatCurrency( (rs_selecciona_ prestamos.Field s.Ite m("loan_amount" ).Value), 2, -2, -2, -2) %></div></td>
    <td class="style6"> <div align="center"> <%= FormatCurrency( (rs_selecciona_ prestamos.Field s.Ite m("earning").Va lue), 2, -2, -2, -2) %></div></td>
    <td class="style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("lend er").Value)%> </div></td>
    <td class="style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("clos ing_date").Valu e)%></div></td>
    <td class="style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("loan _status").Value )%></div></td>
    </tr>
    <%
    Repeat1__index= Repeat1__index+ 1
    Repeat1__numRow s=Repeat1__numR ows-1
    rs_selecciona_p restamos.MoveNe xt()
    Wend
    %>
    [/code]



    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.
    Last edited by markrawlingson; Mar 4 '08, 12:31 AM. Reason: Added code tags. Please use code tags when posting ([code=asp]'some code [/code])
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #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:

    Code:
     <% 
    'Test to see if you want to change the background colour
    If rs("Something") = SomethingElse Then
    sClass = "style6"
    Else
    sClass = "style7"
    End If
    %>
     
    <!-- Then display the table row with the appropriate class -->
    <tr class="<%=sClass%>">
    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

    Comment

    • jullianps
      New Member
      • Feb 2008
      • 7

      #3
      Originally posted by DrBunchman
      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:

      Code:
       <% 
      'Test to see if you want to change the background colour
      If rs("Something") = SomethingElse Then
      sClass = "style6"
      Else
      sClass = "style7"
      End If
      %>
       
      <!-- Then display the table row with the appropriate class -->
      <tr class="<%=sClass%>">
      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!


      [code=asp]

      <% While ((Repeat1__numR ows <> 0) AND (NOT rs_selecciona_p restamos.EOF)) %>
      <%
      dim sClass
      'Test to see if you want to change the background colour
      If (rs_selecciona_ prestamos.Field s.Item("loan_st atus").Value) = "Withdrawn" Then
      sClass = "DeniedWithdraw n"
      Elseif (rs_selecciona_ prestamos.Field s.Item("loan_st atus").Value) = "Processing " Then
      sClass = "style4"
      Else
      sClass = "style1"
      End If
      %>

      <tr class="<%=sClas s%>">
      <td class="Style6"> <div align="center"> <a href="registro_ actividad_edita .asp?loan_id=<% =rs_selecciona_ prestamos("id_f ile")%>"><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.a sp?loan_id=<%=r s_selecciona_pr estamos("id_fil e")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("last _name").Value)% ><%=(rs_selecci ona_prestamos.F ields.Item("nam e").Value)%> </div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("addr ess").Value)%> </div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("PRCO ").Value)%> </div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("PSI" ).Value)%></div></td>
      <td class="Style6"> <div align="center"> <%= FormatCurrency( (rs_selecciona_ prestamos.Field s.Item("loan_am ount").Value), 2, -2, -2, -2) %></div></td>
      <td class="Style6"> <div align="center"> <%= FormatCurrency( (rs_selecciona_ prestamos.Field s.Item("earning ").Value), 2, -2, -2, -2) %></div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("lend er").Value)%> </div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("clos ing_date").Valu e)%></div></td>
      <td class="Style6"> <div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("loan _status").Value )%></div></td>
      </tr>
      <%
      Repeat1__index= Repeat1__index+ 1
      Repeat1__numRow s=Repeat1__numR ows-1
      rs_selecciona_p restamos.MoveNe xt()
      Wend
      %>

      [/code]

      Thanks!
      Marco

      Comment

      • jullianps
        New Member
        • Feb 2008
        • 7

        #4
        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

        [code=asp]

        <% While ((Repeat1__numR ows <> 0) AND (NOT rs_selecciona_p restamos.EOF)) %>
        <%
        dim sClass,valorcam po
        'Test to see if you want to change the background colour
        valorcampo=(rs_ selecciona_pres tamos.Fields.It em("loan_status ").Value)
        'response.write (valorcampo)
        If valorcampo = "Prospect" Then
        sClass = "Prospect"
        'response.Write (sClass)
        Elseif valorcampo = "Processing " Then
        sClass = "Processing "
        'response.Write (sClass)
        Elseif valorcampo = "Closed" or valorcampo = "Funded" Then
        sClass = "CloseFunde d"
        Elseif valorcampo = "Denied" or valorcampo = "Withdrawn" Then
        sClass = "DeniedWithdraw n"
        End If
        %>
        <tr class="<%=sClas s%>">
        <td><div align="center"> <a href="registro_ actividad_edita .asp?loan_id=<% =rs_selecciona_ prestamos("id_f ile")%>"><img src="images/edit_loan.gif" width="22" height="23" border="0" /></a></div></td>
        <td><div align="center"> <a href="registro_ actividad_log.a sp?loan_id=<%=r s_selecciona_pr estamos("id_fil e")%>"><img src="images/loans_log.gif" width="20" height="24" border="0" /></a></div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("last _name").Value)% ><%=(rs_selecci ona_prestamos.F ields.Item("nam e").Value)%> </div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("addr ess").Value)%> </div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("PRCO ").Value)%> </div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("PSI" ).Value)%></div></td>
        <td><div align="center"> <%= FormatCurrency( (rs_selecciona_ prestamos.Field s.Item("loan_am ount").Value), 2, -2, -2, -2) %></div></td>
        <td><div align="center"> <%= FormatCurrency( (rs_selecciona_ prestamos.Field s.Item("earning ").Value), 2, -2, -2, -2) %></div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("lend er").Value)%> </div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("clos ing_date").Valu e)%></div></td>
        <td><div align="center"> <%=(rs_seleccio na_prestamos.Fi elds.Item("loan _status").Value )%></div></td>
        </tr>
        <%
        Repeat1__index= Repeat1__index+ 1
        Repeat1__numRow s=Repeat1__numR ows-1
        rs_selecciona_p restamos.MoveNe xt()
        Wend
        %>

        [/code]


        THANKS FOR THE GREAT HELP
        Marco

        Comment

        • DrBunchman
          Recognized Expert Contributor
          • Jan 2008
          • 979

          #5
          No problem Marco, glad you got it sorted.

          Dr B

          Comment

          Working...