Solved

GridView links in different color format

Posted on 2009-04-13
2
288 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
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 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now