Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GridView links in different color format

Posted on 2009-04-13
2
Medium Priority
?
339 Views
Last Modified: 2012-05-06
Hi all,

I have a gridview, which pulls news titles from our DB, and I am using "< a href" to link it to the news ID.
I need to have different color of fonts on the alternating row.

Please guide me.
The following is my code.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="news_id"
            DataSourceID="SqlDataSource2" Width="226px" BorderStyle="None" 
            BorderWidth="0px" CellPadding="2" Font-Size="10pt"  GridLines="Vertical" Height="146px" ShowHeader="False">
            <Columns>
                <asp:TemplateField InsertVisible="False">
                    <ItemTemplate>
                        <table>
                                    <div id="headlineNew">
                                            <a href='armorenews.aspx?id=<%# DataBinder.Eval(Container.DataItem,"news_id")%>'>
                                                <%# DataBinder.Eval(Container.DataItem, "arnews_title")%>
                                            </a>
                                    </div>
                        </table>
                    </ItemTemplate>
                     <ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" />
                  </asp:TemplateField>
            </Columns>
            <PagerSettings Visible="False" />
			<RowStyle BackColor="#F5F5F5" ForeColor="RED" />
            <AlternatingRowStyle BackColor="#ECECEC" ForeColor="GREEN"/>
        </asp:GridView>

Open in new window

0
Comment
Question by:Wrathyimp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Author Comment

by:Wrathyimp
ID: 24128656
I have tried using the DataNavigateUrlFormatString,
this does changes font color applied from the RowStyle and AlternationRowStyle

the Following is my code:



<asp:GridView ID="GridView2" runat="server" 
		AutoGenerateColumns="False" DataKeyNames="news_id" 
                DataSourceID="News" Height="150px" Width="210px" 
		BorderStyle="None" BorderWidth="0px" CellPadding="0" 
		Font-Size="9pt" GridLines="Vertical" ShowHeader="False" >
	<Columns>
		<asp:TemplateField InsertVisible="False" ShowHeader="False">
	                <ItemTemplate>
				<table>
		                       <div id="headlineNew">                  
			                    <asp:HyperLink ID="HyperLink1" runat="server" 
							Font-Underline="false" 
							DataNavigateUrlFormatString='<%# "morenews.aspx?id=" + DataBinder.Eval(Container.DataItem,"news_id")%>'>
                                            <%# DataBinder.Eval(Container.DataItem, "news_title") %>
                                            </asp:HyperLink>                                                                
                                        </div>
                   	      </table>
                       	</ItemTemplate>
             	</asp:TemplateField>
	</Columns>        
	<PagerSettings Visible="False" />
	<RowStyle BackColor="WhiteSmoke" Font-Bold="True" ForeColor="#AD9147" />
    	<AlternatingRowStyle BackColor="#ECECEC" Font-Bold="false" ForeColor="black" />
</asp:GridView>

Open in new window

0
 
LVL 8

Accepted Solution

by:
bedanand earned 200 total points
ID: 24128680
Use <AlternatingItemTemplate></AlternatingItemTemplate> .
Put the same code as on ItemTemplate with only the color of the link different.

Regards
Bedanand
http://www.dot4pro.com

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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