Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Color - TemplateField - Text 1

Status
Not open for further replies.

sd110404

Programmer
Nov 3, 2004
63
US
Hello Everyone,

Based on my previous post, I need some suggestion. I wasnt sure if I have to continue with the old post or create a new one.

I have a gridview which has the following TemplateField.
Code:
<asp:GridView id="grd" runat="server" OnRowDataBound="grd_RowDataBound">

<asp:TemplateField HeaderText="Closed" SortExpression="Closed">
<ItemTemplate>
<asp:Label ID="lblClosed_Total" runat="server" Text='<%# Bind("Closed_Total") %>' ForeColor="Blue"></asp:Label>
[
<asp:Label ID="lblClosed_High" runat="server" Text='<%# Bind("Closed_High") %>' ForeColor="Red"></asp:Label>
]
</ItemTemplate>

</GridView>

onRowDataBound I need to change the color of [, :, ] text to Black. Else gray all the time.

I have the following code onRowDataBound.

Code:
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }

            Label lbl = (Label)e.Row.FindControl("lblClosed_Total");
            string strLbl;
            strLbl = lbl.Text;
            if (strLbl != "0")
            {
                e.Row.Cells[3].BackColor = Color.Black;

            }

Do I need to use as a label control for "[" text as to change the color? Or is there any other way?

Thanks in advance for any ideas/suggestion.
 
the brackets are plain text. you need to wrap them in a DOM element and apply css. try this instead, it should format the text for you.
Code:
<asp:Label ID="lblClosed_High" runat="server" Text='<%# Bind("Closed_High", "[{0}]") %>' ForeColor="Red" />

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi Jason,

Thank you for your reply/suggestion.

But I need to have the bind("Closed_High") to be displayed in Gray color and the text in black.

The output will look something like this
1[0]

if the first colum is >0 then red ,black, green, black color format.
else all in grey.

Is that still possible with wrapping?

Thanks a lot.
 
then you need to wrap each bracket in a span tag and set the css/style of the span.
Code:
<span class="...">[</span>
<asp:Label ID="lblClosed_High" runat="server" Text='<%# Bind("Closed_High") %>' ForeColor="Red" />
<span class="...">]</span>

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Should I include runat=server in my span control? As I need to change the color based on the Bind value?

Thanks Again.
 
this is your decision. I would use jquery, Skins or some other js library to modify the presentation. however if you want do this on the server then add runat="server" and set an id. then you will need to do all the finding/casting/styling in the code behind.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason, I am sorry, I am just getting to know more in c#. Will you be able to tell me how do I do this in client side? I mean when the value of Bind("Closed_High") is > 0 i need to change the color.
Thanks.
 
for better, or worse, my apps don't need to be pretty, so css and js are lacking. I would start by understanding the basics of css and js. Then check out jquery.

this seems overkill, but you could use labels for the bracket text and set the style of these labels in code behind.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you for all the time you spend here in replying.
For now I am going to use Lable control like you mentioned. But I would like to know more about JQuery. Have some knowledge on css and js. But I guess tahts not enough.
Also I had tried to change the css of Span in Server side. But i was not able to find the control Span.
Anyway I am going to use Label for now. And will do more reserch afterwards.
Thanks Again for all ur help.
 
Span by itself is not an object. I can't remember the exact type of control off hand, but it's something like Literal or HtmlControl.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top