Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 03, 2013 02:28 PM by Ramu Ajay
Member
24 Points
39 Posts
Jan 02, 2013 03:34 PM|LINK
Based on one column value .. i need to change the forecolor of gridview....
All the other fields color changes except that of hyperlink.
How do i change the color of hyperlink in Gridview??
120 Points
220 Posts
Jan 02, 2013 03:52 PM|LINK
if your condition { yourhyperlink.CssClass = "yourcssclass";}.youcsscladd{//Css for yourhyperlink}
if your condition { your
your
623 Points
203 Posts
Jan 02, 2013 08:56 PM|LINK
If you have a HyperLink do you want to show the GridView row in Diff color or just based on One column Value?
Can you be more precise?
Star
14412 Points
2452 Posts
Jan 03, 2013 05:10 AM|LINK
Hi,
Try these Pseudo-classes:
http://www.w3schools.com/css/css_pseudo_classes.asp
mainly, a:link{...}
408 Points
74 Posts
Jan 03, 2013 10:20 AM|LINK
gridView tr td a{ color: #yourColor; }
Jan 03, 2013 12:47 PM|LINK
For each row of gridview accondition will be checked....for each column...if the column value is say 1...the row color changes otherwise not...
I have a hyperlink in each row.....the color of hyperlink is not changing.....rest of the text color changes.
Participant
942 Points
178 Posts
Jan 03, 2013 12:59 PM|LINK
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1" ondatabound="GridView1_DataBound" onrowdatabound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> <asp:BoundField DataField="ParentID" HeaderText="ParentID" SortExpression="ParentID" /> <asp:BoundField DataField="Content" HeaderText="Content" SortExpression="Content" /> <asp:BoundField DataField="ShortContent" HeaderText="ShortContent" SortExpression="ShortContent" /> <asp:TemplateField HeaderText="Status" ControlStyle-Width="75px" > <ItemTemplate> <asp:Hyperlink ID="h1" runat="server" NavigateUrl='<%# Bind("ParentID") + Request.QueryString("type") %>'></asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data/Database1.accdb" SelectCommand="SELECT CMSMenus.ID, CMSMenus.Title, CMSMenus.Location, CMSMenus.ParentID, CMSMenus.Content, CMSMenus.ShortContent FROM CMSMenus; "> </asp:AccessDataSource>
For Code behind here is the code behind I coloured the hyperlink cells depends on column ParentID value you can choose your own
protected void GridView1_DataBound(object sender, EventArgs e) { for (int i =0 ; i <= GridView1.Rows.Count -1 ;i++) { HyperLink lblparent = (HyperLink)GridView1.Rows[i].FindControl("h1"); if (lblparent.Text == "1") { GridView1.Rows[i].Cells[6].BackColor = Color.Yellow; lblparent.ForeColor = Color.Black; } else { GridView1.Rows[i].Cells[6].BackColor = Color.Green; lblparent.ForeColor = Color.Yellow; } } }
Jan 03, 2013 02:28 PM|LINK
Did you Tried?
HyperLink1.ForeColor = System.Drawing.Color.Red;
and morever as you know the control is not accesible directly in the page as it resided in GridView. You need to Access it by using your GridView properties/GridView Row properties
swati_jus4u
Member
24 Points
39 Posts
Changing the color of hyperlink in Gridview.
Jan 02, 2013 03:34 PM|LINK
Based on one column value .. i need to change the forecolor of gridview....
All the other fields color changes except that of hyperlink.
How do i change the color of hyperlink in Gridview??
Happy Coding !!
Shanker_YPSS
Member
120 Points
220 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 02, 2013 03:52 PM|LINK
Ramu Ajay
Member
623 Points
203 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 02, 2013 08:56 PM|LINK
If you have a HyperLink do you want to show the GridView row in Diff color or just based on One column Value?
Can you be more precise?
raju dasa
Star
14412 Points
2452 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 03, 2013 05:10 AM|LINK
Hi,
Try these Pseudo-classes:
http://www.w3schools.com/css/css_pseudo_classes.asp
mainly, a:link{...}
rajudasa.blogspot.com || blog@opera
saeed_saedva...
Member
408 Points
74 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 03, 2013 10:20 AM|LINK
gridView tr td a{ color: #yourColor; }Saeed Saedvand
swati_jus4u
Member
24 Points
39 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 03, 2013 12:47 PM|LINK
For each row of gridview accondition will be checked....for each column...if the column value is say 1...the row color changes otherwise not...
I have a hyperlink in each row.....the color of hyperlink is not changing.....rest of the text color changes.
Happy Coding !!
NadeemZee
Participant
942 Points
178 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 03, 2013 12:59 PM|LINK
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1" ondatabound="GridView1_DataBound" onrowdatabound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> <asp:BoundField DataField="ParentID" HeaderText="ParentID" SortExpression="ParentID" /> <asp:BoundField DataField="Content" HeaderText="Content" SortExpression="Content" /> <asp:BoundField DataField="ShortContent" HeaderText="ShortContent" SortExpression="ShortContent" /> <asp:TemplateField HeaderText="Status" ControlStyle-Width="75px" > <ItemTemplate> <asp:Hyperlink ID="h1" runat="server" NavigateUrl='<%# Bind("ParentID") + Request.QueryString("type") %>'></asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data/Database1.accdb" SelectCommand="SELECT CMSMenus.ID, CMSMenus.Title, CMSMenus.Location, CMSMenus.ParentID, CMSMenus.Content, CMSMenus.ShortContent FROM CMSMenus; "> </asp:AccessDataSource>For Code behind here is the code behind I coloured the hyperlink cells depends on column ParentID value you can choose your own
protected void GridView1_DataBound(object sender, EventArgs e) { for (int i =0 ; i <= GridView1.Rows.Count -1 ;i++) { HyperLink lblparent = (HyperLink)GridView1.Rows[i].FindControl("h1"); if (lblparent.Text == "1") { GridView1.Rows[i].Cells[6].BackColor = Color.Yellow; lblparent.ForeColor = Color.Black; } else { GridView1.Rows[i].Cells[6].BackColor = Color.Green; lblparent.ForeColor = Color.Yellow; } } }Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
Ramu Ajay
Member
623 Points
203 Posts
Re: Changing the color of hyperlink in Gridview.
Jan 03, 2013 02:28 PM|LINK
Did you Tried?
HyperLink1.ForeColor = System.Drawing.Color.Red;
and morever as you know the control is not accesible directly in the page as it resided in GridView. You need to Access it by using your GridView properties/GridView Row properties