I have a control that look something like this:
<asp:DetailsView ID="dvUsers" runat="server" DataSourceID="odsData"
DataKeyNames="Id">
...
</asp:DetailsView>
Which in the end will create a <table> as the outer-most element. In my CSS I have:
table tr {
border-top: 0 ;
border-left: 0 ;
border-right: 0 ;
border-bottom-width: 1px;
}
Now when I run the web-site the rendered <table> will have borders and styles which is due to the default settings for the control, which looks like this
<table cellspacing="0" rules="all" border="1" id="ctl00_body_dvUsers"
style="border-collapse:collapse;">
This will obviously override my CSS since it is inline and I do not want this. Is there any way of turning of all of the styling that is automatically done? I guess that I could receive the same result as my CSS by setting a lot of attributes on the DetailsView,
but I might have a lot of controls which in the end would render the final output as a table and I would have to configure all of these the same way.
This would result in a lot of duplicate code and a lot of work if some designer want to change the style of all the tables, since I would have to go back and change the styles for every control in my Theme file.
Is there a way of saying “Don´t mess with the styles, I know what I am doing!” ?
Take a look at the CSS Friendly Control Adapters project. It provides a drop-in solution to convert the DetailsView control (and others) from a table-based design a to div-based design that uses CSS classes instead of inline styles.
So, for example, it automagically turns this headache-inducing code:
into peace and serenity:
I’ve been using it successfully for a while now, highly recommend it.