Solved

apply css style to details view on edit

Posted on 2014-01-27
5
558 Views
Last Modified: 2014-01-27
Hello I have a question, would someone be able to explain to me how to apply alternate row colors to a details view when in edit mode?

I am not finding information about this, maybe because using wrong keywords for search.

Any help would be nice, if examples provided even better!

Thank you much!
0
Comment
Question by:metropia
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39812439
You would use nth child https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#Example_selectors and you can simply use nth-child(odd)

table#MyTable{
  tr:nth-child(odd)
}

Open in new window

0
 

Author Comment

by:metropia
ID: 39812483
is this to be applied to a detaileview control on a asp.net form?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39812503
That is your external style sheet.   Your rendered code would look like http://jsbin.com/EtIQUWeQ/1/edit

I am not a .net dev but I think your table would be

<asp:Table id="MyTable"  runat="server" />

The external css would create the formatting.
<!DOCTYPE html>
<html>
<head>
 <style>
   table#MyTable
   tr:nth-child(odd){background-color:red;
}
  </style>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="MyTable">
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    
  </table>
</body>
</html>

Open in new window

0
 

Author Comment

by:metropia
ID: 39812544
i see. it sort of works.

the thing is that i need the style only applied when the details view is on Edit mode.
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39812626
When you go to edit mode, add a class.  http://jsbin.com/EtIQUWeQ/2/edit

Here is the same thing but applying to a class called "edit".  When it the table is not in edit mode:    <table id="MyTable"> and when in edit mode  <table id="MyTable" class="edit">  You may need to do this with js/jquery or if you are doing a page refresh to get to edit mode, then add the class via your serverside code.

<!DOCTYPE html>
<html>
<head>
 <style>
   table#MyTable.edit
   tr:nth-child(odd){background-color:red;
}
  </style>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table id="MyTable" class="edit">
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    <tr><td>stuff</td></tr>
    
  </table>
</body>
</html>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now