Solved

apply css style to details view on edit

Posted on 2014-01-27
5
528 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

16 Experts available now in Live!

Get 1:1 Help Now