How do I make table data red in <td>?
-
There is this code that have a name in the table data and I have been asked to make that data red. Right now it is bold (strong). I need to add code to also make it appear read. How do I do this? Here is the code in C#
<%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ? "" : "**Pro Se**" %>
" + Eval("AttorneyFullName") + "
-
There is this code that have a name in the table data and I have been asked to make that data red. Right now it is bold (strong). I need to add code to also make it appear read. How do I do this? Here is the code in C#
<%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ? "" : "**Pro Se**" %>
" + Eval("AttorneyFullName") + "
Why are you inserting a single-cell table? Just wrap the value in a
<span>
or a<div>
, and set a suitable CSS class on it. You'll also need to HTML encode the value from the database, just in case.<ItemTemplate>
<%#
Eval("AttorneyPartyID", "{0}") != Eval("PartyID", "{0}")
? "<div class=\"attorney-full-name\">" + HttpUtility.HtmlEncode(Eval("AttorneyFullName", "{0}")) + "</div>"
: "Pro Se"
%>
</ItemTemplate>.attorney-full-name {
color: #a00;
font-weight: bold;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Why are you inserting a single-cell table? Just wrap the value in a
<span>
or a<div>
, and set a suitable CSS class on it. You'll also need to HTML encode the value from the database, just in case.<ItemTemplate>
<%#
Eval("AttorneyPartyID", "{0}") != Eval("PartyID", "{0}")
? "<div class=\"attorney-full-name\">" + HttpUtility.HtmlEncode(Eval("AttorneyFullName", "{0}")) + "</div>"
: "Pro Se"
%>
</ItemTemplate>.attorney-full-name {
color: #a00;
font-weight: bold;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
It is not a single-cell. I did not paste the whole table (ItemTemplate). The table has 5 rows and each row has a single (cell) Here is the whole table
<%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ? "" : "**Pro Se**" %> <%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() && Eval("AttorneyPhoneNumber") != "" && Eval("AttorneyPhoneNumber") != null ? "" : string.Empty %> <%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() && Eval("AttorneyEmail") != "" && Eval("AttorneyEmail") != null ? "" : string.Empty %> <%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ? "
" + Eval("AttorneyFullName") + "
Phone:" + ' ' + Eval("AttorneyPhoneNumber") + "
Email:" + Eval("AttorneyEmail") + "
"
:
string.Empty
%> -
It is not a single-cell. I did not paste the whole table (ItemTemplate). The table has 5 rows and each row has a single (cell) Here is the whole table
<%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ? "" : "**Pro Se**" %> <%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() && Eval("AttorneyPhoneNumber") != "" && Eval("AttorneyPhoneNumber") != null ? "" : string.Empty %> <%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() && Eval("AttorneyEmail") != "" && Eval("AttorneyEmail") != null ? "" : string.Empty %> <%# Eval("AttorneyPartyID").ToString() != Eval("PartyID").ToString() ? "
" + Eval("AttorneyFullName") + "
Phone:" + ' ' + Eval("AttorneyPhoneNumber") + "
Email:" + Eval("AttorneyEmail") + "
"
:
string.Empty
%>You still need to HTML-encode the database values. And the solution to your original question is still the same: add a CSS class to the parent element of the text you want to style. I also think you can tidy that code up somewhat, and avoid having to build the HTML as a string:
<asp:TemplateField HeaderText="Attorney" HeaderStyle-HorizontalAlign="Justify" ItemStyle-Width="25%">
<ItemTemplate>
<asp:MultiView runat="server" ActiveViewIndex='<%# Eval("AttorneyPartyID", "{0}") != Eval("PartyID", "{0}") ? 0 : 1 %>'>
<asp:View runat="server">
<table>
<tr>
<td class="attorney-full-name"><%#: Eval("AttorneyFullName") %></td>
</tr>
<asp:Placeholder runat="server" visible='<%# !string.IsNullOrEmpty(Eval("AttorneyPhoneNumber", "{0}")) %>'>
<tr>
<td class="attorney-phone-number">Phone: <%#: Eval("AttorneyPhoneNumber") %></td>
</tr>
</asp:Placeholder>
<asp:Placeholder runat="server" visible='<%# !string.IsNullOrEmpty(Eval("AttorneyEmail", "{0}")) %>'>
<tr>
<td class="attorney-email">Email: <%#: Eval("AttorneyEmail") %></td>
</tr>
</asp:Placeholder>
</table>
</asp:View>
<asp:View runat="server">
Pro Se
</asp:View>
</asp:MultiView>
</ItemTemplate>
</asp:TemplateField>NB: Using
<%#: ... %>
instead of<%# ... %>
- note the extra:
at the start - will automatically HTML-encode the output for you. MultiView Class (System.Web.UI.WebControls) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
You still need to HTML-encode the database values. And the solution to your original question is still the same: add a CSS class to the parent element of the text you want to style. I also think you can tidy that code up somewhat, and avoid having to build the HTML as a string:
<asp:TemplateField HeaderText="Attorney" HeaderStyle-HorizontalAlign="Justify" ItemStyle-Width="25%">
<ItemTemplate>
<asp:MultiView runat="server" ActiveViewIndex='<%# Eval("AttorneyPartyID", "{0}") != Eval("PartyID", "{0}") ? 0 : 1 %>'>
<asp:View runat="server">
<table>
<tr>
<td class="attorney-full-name"><%#: Eval("AttorneyFullName") %></td>
</tr>
<asp:Placeholder runat="server" visible='<%# !string.IsNullOrEmpty(Eval("AttorneyPhoneNumber", "{0}")) %>'>
<tr>
<td class="attorney-phone-number">Phone: <%#: Eval("AttorneyPhoneNumber") %></td>
</tr>
</asp:Placeholder>
<asp:Placeholder runat="server" visible='<%# !string.IsNullOrEmpty(Eval("AttorneyEmail", "{0}")) %>'>
<tr>
<td class="attorney-email">Email: <%#: Eval("AttorneyEmail") %></td>
</tr>
</asp:Placeholder>
</table>
</asp:View>
<asp:View runat="server">
Pro Se
</asp:View>
</asp:MultiView>
</ItemTemplate>
</asp:TemplateField>NB: Using
<%#: ... %>
instead of<%# ... %>
- note the extra:
at the start - will automatically HTML-encode the output for you. MultiView Class (System.Web.UI.WebControls) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thank for your help on trying to figure this out. I did add css class to existing css file.
.inactiveAttorney
{
color: #AD0000;
font-weight:bold
}The product owner have asked me to only make the attorney name red when fActive = 0 (false). The code behind have this code
private bool _fActive;
public bool fActive
{
get { return this._fActive; }
set { this._fActive = value; }
}
this._fActive = parsefActive == true ? true : false; //This is how it is called or populatedI have successfully been able to use css class to make attorney name red. However, I need help to add a condition so that the name is red only when fActive =false (0). Here is my code which is working and needs adding condition
"
" + Eval("AttorneyFullName") + "
"
The fActive is a Boolean and else where in the code I see something done when a Boolean is true. I need to do something similar but I do not know how. Here is that example.
<%# (bool)Eval("PartyConfidentialHomePhone") == true ? "
":"" %><%#Eval("PartyHomePhone").ToString() != "" && Eval("PartyHomePhone") != null ? "" + Eval("PartyHomePhone") + "":string.Empty%>
-
Thank for your help on trying to figure this out. I did add css class to existing css file.
.inactiveAttorney
{
color: #AD0000;
font-weight:bold
}The product owner have asked me to only make the attorney name red when fActive = 0 (false). The code behind have this code
private bool _fActive;
public bool fActive
{
get { return this._fActive; }
set { this._fActive = value; }
}
this._fActive = parsefActive == true ? true : false; //This is how it is called or populatedI have successfully been able to use css class to make attorney name red. However, I need help to add a condition so that the name is red only when fActive =false (0). Here is my code which is working and needs adding condition
"
" + Eval("AttorneyFullName") + "
"
The fActive is a Boolean and else where in the code I see something done when a Boolean is true. I need to do something similar but I do not know how. Here is that example.
<%# (bool)Eval("PartyConfidentialHomePhone") == true ? "
":"" %><%#Eval("PartyHomePhone").ToString() != "" && Eval("PartyHomePhone") != null ? "" + Eval("PartyHomePhone") + "":string.Empty%>
Try:
"<table><tr><td class='" + (fActive ? "activeAttorney" : "inactiveAttorney") + "'>" + Eval("AttorneyFullName") + "</td></tr></table>"
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Try:
"<table><tr><td class='" + (fActive ? "activeAttorney" : "inactiveAttorney") + "'>" + Eval("AttorneyFullName") + "</td></tr></table>"
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Hi Homer, Thanks for your reply. When I tried the code you gave me, I am getting an error The name "fActive" does not exist in the current context
-
Hi Homer, Thanks for your reply. When I tried the code you gave me, I am getting an error The name "fActive" does not exist in the current context
Then the code-behind of the page or user control where the data-binding is taking place doesn't have the property you showed in your previous message.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Then the code-behind of the page or user control where the data-binding is taking place doesn't have the property you showed in your previous message.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Here is the code behind that have the fActive
private bool _fActive;
public bool fActive
{
get { return this._fActive; }
set { this._fActive = value; }
}
bool parsefActive = false;Boolean.TryParse(row["fActive"].ToString(), out parsefActive);
this._fActive = parsefActive == true ? true : false; //This is how it is called or populated -
Here is the code behind that have the fActive
private bool _fActive;
public bool fActive
{
get { return this._fActive; }
set { this._fActive = value; }
}
bool parsefActive = false;Boolean.TryParse(row["fActive"].ToString(), out parsefActive);
this._fActive = parsefActive == true ? true : false; //This is how it is called or populatedAs I said, that doesn't tally with the error message:
The name "fActive" does not exist in the current context
That property does not exist in the code-behind for the page or user control where your data-binding is taking place.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
As I said, that doesn't tally with the error message:
The name "fActive" does not exist in the current context
That property does not exist in the code-behind for the page or user control where your data-binding is taking place.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Hi everybody who tried to help me on this problem. I wanted to thank you for trying to help. However after hours of try and error, I found a solution that works. Just wanted to let you know this is now fixed. Here is my solution. Looks pretty simple! So the logic is, if AttorneyPartyID = PartyID that is Pro Se, else if fActive is false that means the attorney is inactive. Use inactiveAttorney css class to display attorney name with red font else the attorney is active and no need to display name in red font. Display in bold font.
<%#
Eval("AttorneyPartyID").ToString() == Eval("PartyID").ToString()
? "Pro Se"
: (bool) Eval("fActive") == false
? "" /*This is inactive attorney*/
:"" + Eval("AttorneyFullName") + "
" /*This is Active attorney*/
%>" + Eval("AttorneyFullName") + "