Visual Studio 2010 does not follow my CSS ... help pls - asp.net

here is my CSS:
.body
{
font-family : Segoe UI;
}
.table{
width : 50%;
font-size:medium;
border-spacing:5px;
}
.leftCol
{
width:15%
}
.RightCol
{
width:35%
}
.header
{
width:35%;
font-weight:900;
text-align:left;
}
.dates
{
color:GrayText;
font-size:small
}
.pictures
{
width:10%;
}
.userName
{
width:10%;
text-align:left;
}
.smallTable
{
width:20%;
}
Here is the HTML markup:
<table class=".table">
<tr>
<td rowspan="3" class=".leftCol">
<asp:Label ID="ImageLabel" runat="server" Text='<%# Eval("Image") %>' />
</td>
<td class=".header">
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
</tr>
<tr>
<td class=".rightCol">
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
</tr>
<tr>
<td class=".dates">
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</table><hr />
the other one:(this table width actually works)
<table class=".smallTable">
<tr >
<td class=".pictures">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Pictures") %>' /></td>
<td class=".userName" align="left">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' /></td>
</tr>
</table><hr />
so, instead of following the rules, VS uses 100% width for the table using .table class, and then it just arranges in justified. The dates does not appear in gray colour ... and basically nothing follows. But i can assure you that the class names i wrote and everything is correct as i check. It just doesnt work . Do you know anyway i can force VS 2010 to do this ?

In all class that you declare on the tags you must place them with out the dot. Eg:
<table class="smallTable">
and change the class name .table to something else because the table is reserve for all tables and probably this type of variables lead to bugs. Do not mix up the tag names with the css declare.
The css table{ width : 50%; } change all the tables on the page.
The css body{ font-family : Segoe UI; } change all the body fonts.
The css .body{ font-family : Segoe UI; } is change only what you declare on class as body but eventually can lead to bugs and errors .

Related

Style table in repeater from code behind

Hey guys I need some help with an application that I'm developing.
I'm trying to add a css class / styling to a table depending on a certain value that I'm getting from the database ( e.g. 0 - 2).
This is the code where I need to change the styling of the table
Public Function projectType(ByVal value As Integer)
Dim projectName As String
If value = 0 Then
projectName = "Project"
mytable.AddAttributes("Style", "Background-color:#444444")
ElseIf value = 1 Then
projectName = "Support"
Else
projectName = "Not available"
End If
Return projectName
End Function
Markup:
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="1"
RepeatDirection="Vertical" CellPadding="0" CellSpacing="0">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" style="width: 100%; text-align: left; border-bottom: 1px solid #999999;
padding-bottom: 15px;">
<tr>
<td style="width: 110px; vertical-align: top; padding-left: 20px; padding-top: 5px;
padding-bottom: 5px;">
<asp:Label ID="Label5" runat="server" Text='<%# projectType(Eval("Type")) %>' Font-Names="Verdana"
Font-Size="9pt" EnableTheming="false" />
</td>
<td style="width: 110px; vertical-align: top; padding-left: 20px; padding-top: 5px;
padding-bottom: 5px;">
<asp:Label ID="Label2" runat="server" Text='<%# hoursCheck(Eval("Duration")) %>'
Font-Names="Verdana" Font-Size="9pt" Style="text-align: right" EnableTheming="false" />
</td>
</tr>
<tr>
<td colspan="2" style="padding-bottom: 5px; padding-top: 5px; text-align: center">
<asp:Label ID="Label7" runat="server" Text='<%# Eval("FullName") %>' Font-Names="Verdana"
Font-Size="7pt" EnableTheming="false" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
From this function I need to access the table by getting the parent table of the sender since I can't explicitly say I want Datalist1 since I have 5 of them, how can I do this?
First of all, please get rid of inline styles and replace them with CSS classes. Will save you a lot of headache later on. For instance, have two CSS classes, one for "Project", another for "Support" and "Not available"
As for the actual question, the easiest thing that comes to mind is to split the logic into two functions, one for text and one for css class:
Public Function projectTypeText(ByVal value As Integer)
...
Return projectName
End Function
Public Function projectTypeClass(ByVal value As Integer)
...
Return projectCssClass
End Function
And then use it exactly as you did:
<%-- This might actually need runat="server", not sure --%>
<table cellpadding="0" cellspacing="0" style='<%# projectTypeClass(Eval("Type")) %>'
<asp:Label ID="Label5" runat="server" Text='<%# projectType(Eval("Type")) %>'
Note: if you absolutely have to deal with inline classes, you can have projectTypeStyle which returns Background-color:#444444, but then inside the markup you will need to do nasty stuff like that:
<table cellpadding="0" cellspacing="0" style='<%# "width: 100%; rest of styles; " + projectTypeStyle(Eval("Type")) %>'
This is horrible, so please avoid at all cost.

Styling Listview in asp.net

I have got a listview which is styled with css but dosent work.Am I missing something here.
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<tr class="myitem">
<td> <asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /> </td>
</tr>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
</ItemTemplate>
</asp:ListView>
Here is the css
.myitem
{
background-color:Red;
}
Table rows (tr) can't be styled as other elements (e.g. table cells (td)), meaning they don't react on every kind of styling. Why don't you just write:
Fiddle
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<table>
<tr class="myitem">
<td>
<asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' />
</td>
</tr>
</table>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%></ItemTemplate>
</asp:ListView>
tr.myitem td{
width:200px;
height:20px;
border:2px solid;
background:red;
}
OR
Fiddle
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<table>
<tr class="myitem">
<td>
<asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' />
</td>
</tr>
</table>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%></ItemTemplate>
.myitem {
background:red;
}
EDIT
You need to add <table> tag

how to remove space under a table?

Here what I've done and whats my problem. First of all i got a big table with a lot of td the first td on top of my table containt anoter table and (here come my problem) theres a space under that little table and I don't know why.
Here's the code for my table:
<div runat="server" class="ReportPage" >
<table runat="server" class="ListReportBigTable" align="center">
<tr>
<td class="style13" colspan="3" >
<table width="46%" align="center"style="height:50%; "cellpadding="0">
<tr>
<td align="left">
<asp:Label ID="LB_ChooseReport" runat="server"
Text="Choisissez un dossier médical: " Font-Size="Small">
</asp:Label>
</td>
</tr>
<tr>
<td style="vertical-align:bottom" align="left">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<div id="div_Filter" runat="server" visible="false" align="left">
<asp:Label ID="LBL_FilteredBy" runat="server" width="18%" Text="Patient : "
Font-Size="Small" style="margin-left: 0px"></asp:Label>
<asp:DropDownList ID="DDL_FilterSelect" runat="server" AutoPostBack="true"
Width="25%" CssClass="DDL_Filter" Font-Size="Small" Height="18px"></asp:DropDownList>
</div>
</ContentTemplate>
</asp:UpdatePanel></td></tr></table>
<br />
</td>
and here the CSS:
.ListReportBigTable
{
height:25%;
width:55%;
text-align:center;
vertical-align:middle;
border: thick solid black;
margin-left: 0px;
}
thx in advance
I don't know if it's a typo but you are closing with a </td> after your closing </table> tag. In addition you have a <br /> before the closing misplaced </td> which would obviously add space to the bottom.
Try changing the closing </td> to </table></div> and removing the <br />
In addition, in your CSS try adding margin-bottom: 0px; and padding-bottom: 0px; to see if this has an effect.
Also, what is after the table? Maybe whatever is being displayed after the table has it's own top margin/padding?
Do you have a link to the actual page where this is occuring so we can examine with Firebug or similar and try to figure it out?

Formatting Gridview display in ASPX page

Scenario : I have an ASPX page with Gridview. Every row has one column heading and it's value. At the end of record there is a generic line.
My issue is with formatting and CSS.
I would like the output to be as below (I have tried to format but upon posting it is loosing)
| Customer Name | Microsoft |
| Customer City | Seattle |
| |
| Customer Name | DowJones |
| Customer City | NYC |
Above the customer name is centered to that cell. Similarly it's value also (Microsoft). Also CustomerName is colored with darkblack and "Microsoft" with just black.
The '-----' and "|" are actually table borders/seperators. It is typical table with borders and horizontal line and vertical line.
Please suggest. Below is my code.
<div style="width:400px; font-family:Arial; font-size:small">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="100%" GridLines= "Horizontal">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div style="color:Blue;font-weight:bold">
<br />
<tr>
<td><asp:Label ID="Label5" runat="server" Text='Customer NAME' cssclass ="blackboldhdr" ></asp:Label></td>
<td><asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"DealerName") %>' cssclass ="blackboldtxt"></asp:Label></td>
</tr>
<tr>
<td><asp:Label ID="Label2" runat="server" Text='Customer City'></asp:Label></td>
<td><asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"City") %>'></asp:Label></td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<style>
.blackboldtxt {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color:black;
font-weight: bold;
}
.blackboldhdr
{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
/*color:#FFFFFF;*/
background-color: #2A3C54;
width: 152px;
text-align:center;
}
</style>
I don't think you can use <tr> and <td> elements inside the grid's itemTemplate. Since the grid will already render <tr>...</tr> for each row and <td> {Item template's content} </td>, the result would be invalid HTML code.
I think you should use a Repeater instead of the Grid, e.g. something like this:
<asp:Repeater>
<HeaderTemplate><table class="..."></HeaderTemplate>
<ItemTemplate>
<tr>
<td class="blackboldhdr">
<asp:Label runat="server" Text='Customer NAME' cssclass="blackboldhdr"/>
</td>
<td>
<asp:Label runat="server" cssclass ="blackboldtxt"
Text='<%#DataBinder.Eval(Container.DataItem,"DealerName") %>' />
</td>
</tr>
<tr>
... same as above, but for customer address
</tr>
</ItemTemplate>
<SeparatorTemplate><tr><td colspan="2"> </td></tr>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>

How to give border line to single td element in the table tr element?

I have a table in ASP.Net like this.
<table width="100%">
<tr>
<td rowspan="4" colspan="2" class="style1">
</td>
<td>
<asp:Label ID="label1" runat="server" Text="Label1"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" Width="136px">
</asp:TextBox>
</td>
</tr>
<tr>
<td><asp:Label ID="label2" runat="server" Text="Label2"></asp:Label></td>
<td><asp:TextBox ID="TextBox1" runat="server" Width="136px">
</asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="label3" runat="server" Text="Label3"></asp:Label></td>
<td><asp:TextBox ID="TextBox2" runat="server" Width="136px">
</asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="label4" runat="server" Text="Label4"></asp:Label></td>
<td><asp:TextBox ID="TextBox3" runat="server" Width="136px">
</asp:TextBox></td>
</tr>
</table>
I want to give border line to first td element which contains the colspan and rowspan. Not to the entire row.
Please give solution.
If you want border only on the td with class style1 :
table, tr, td { border: none; }
td.style1 { border: 1px solid black; }
Try jquery http://jquery.com/
Add this in your head
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
then add this in the body
<script>
$('table tr td:first').css('border','1px solid');
<script/>
Set this style on the td:
<style type="text/css">
.firsttd { border-color: #000000; border-style: solid; }
</style>
...
<td class="firsttd" rowspan="4" colspan="2" >

Resources