Make Gridview cell value a hyperlink and change color of font conditional

Hello:

I have a gridview displaying information about a project.  One of the columns of the record is the unique "id" and another column called "status" is the status of that record (i.e. New, Queue, Approved, etc).  I would like to do the following in VB code behind...

If the Status of the record is equals "Queue" then make the font color of the word "Queue" maroon and make the word "Queue" a hyperlink to another page and pass the unique id of that record to that page.  I can get this to work with an edit button but not with my custom column called Status.

Thank you in advance!

0
ckcasp
10/2/2007 8:02:27 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
799 Views

Similar Articles

[PageSpeed] 30

for the color:
    Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
         If e.Row.RowType = DataControlRowType.DataRow Then
            If e.Row.Cells(2).Text.Trim = "Queue" Then
                e.Row.Cells(2).forecolor = Color.Maroon
            End If     
         End If
    End Sub 

Then, point to the doColor routine in your Gridview's OnRowDataBound event:
OnRowDataBound="doColor"

I don't have a sample for the hyperlink just yet


David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Please Vote for ASPNet101 - 'Best Community Resource'!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
0
augustwind
10/2/2007 8:19:18 PM

Good afternoon, I am assuming you are using a template column for your status value.  If this is the case, in this status column add a label control and a hyperlink control.  Then in the RowDataBound event of the GridView you can check to see what the status of the record is and handle the showing and hiding of the label and hyperlink as well as setting the hyperlinks navigateurl property to pass the current id of the record.  You can also easily set the FontColor of both controls.

Hope this helps.

 Regards,
Michael Reyeros


--------------------------------------------------
Sincerely,
Michael Reyeros

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

If my solution doesn't solve your problem, just feel free to mark it as not answer and reply.
0
mreyeros
10/2/2007 8:21:06 PM

Hi Everyone:

This may not be the best solution, but I am on a deadline...

 

Unfortunately the forecolor code was not successful (do to a CSS?).  I was getting a white forecolor and would turn blue on hover over.

 

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

Dim x As Integer

x = 0

'Find all records with Status=Queue and change backcolor of status to Red to indicate editable

If e.Row.RowType = DataControlRowType.DataRow Then

For x = 0 To e.Row.Cells.Count - 1

If e.Row.Cells(x).Text = "Queue" Then

Dim h1 As New HyperLink()

h1.Text = e.Row.Cells(x).Text

'Get the unique id for the request from the first column

Dim strID As String = "http://localhost/myprojectfolder/Edit.aspx?id=" & e.Row.Cells(0).Text

h1.NavigateUrl = strID

h1.Target = "_blank"

h1.ToolTip = "Click to Edit this Project Request."

h1.Style.Add("background-color", "maroon")

e.Row.Cells(x).Controls.Add(h1)

End If

Next

End If

End Sub

 

 Thanks for all your help!

 

0
ckcasp
10/3/2007 12:54:48 PM
Reply:

Similar Artilces:

how do I conditionally change bkg color of datalist cell and make the content of the cell clickable
Hi all, 1) how do I change background color of a datalist cell based on an attribute value (of a xml file) and make the content of the cell clickable ? 2) assuming the datalist is in an iframe. How do I make the cell content value available to another iframe page via clickable/url passing technique?  Thanks Here's how to change the color (BALANCE_COL is the cell index): protected void GridViewFun_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.DataIt...

Colorize gridview cell by value present
Hi all.. I am collecting data from a PLC, it writes a 1,2 or 3 to the database.  From this I wish to highlight a cell in a gridview.  Below is the code I have tried. If the 3rd cell in the gridview = 3 then RED, but it doesn't work, and I get no error.  Any ideas on what I might be doing wrong? Thanks in advance   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.Cells[3]).Text == ("3")) { ...

change one gridview cell text format based on another gridview cell value??
I have the following (I code in VB) in a datagrid nested inside a DataList: The hiddencolumn style prevents the CAB column/data field from showing in the browser. How do I make the "Consumer" datafield cell text be purple and italic if CAB is True or -1 in Access?? I code in VB, and I know the code has to be in the one of the row or data events of the gridview. Thank you, Tom Convert your Consumer to a template field with label, id = "Label1" then try using the RowDataBound event of the gridview and code something like: If e.Row.RowType = DataControlRowType.Data...

Gridview
Hi, I have a GridView, that I want to change the color of the cell if the value of the bound field equals "Completed" - <asp:GridView ID="gdViewAllopen" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="5" DataKeyNames="id" DataSourceID="SqlDataSource_view_open" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" ForeColor="Black" OnRowDataBound="gdViewAllopen_RowDataBound"> <Columns> <asp:Bo...

Change row and font color in Gridview based on DataField Value
I would like to set the row color and font color on my Gridview based on a datafield value  Here is my GridView <asp:GridView ID="ordersGridView" runat="server" AutoGenerateColumns="false" CellPadding="1" AllowSorting="True" datakeynames="ORDER_ID">    <Columns>                <asp:CommandField ShowSelectButton="True" />                <asp:BoundField DataField="ORDER_TYPE_NAME" HeaderText="Order Type...

generate excel file, how to change the font color of the cells by the values in it?
I'm using CarlosAgExcelWriter to create excel files. The values in the cell will be strings or decimals. I wonder how can I change the negative decimal value cell's font color to red?         report[0, 0] = "Spend";        report[0, 1] = " ";        report[0, 2] = " ";        report[0, 3] = " ";        report[0, 4] = " ";       ...

How to make GridView items hyperlink and change bgcolor on line items with condition
I have a gridview that is bound to an object data source. The challenge I ran into is to make the displayed entries hyperlink to open ViewTicket.aspx page with a parameter.  ViewTicket.aspx?TicketID=" + gvMain.SelectedValue.ToString If a ticket is with 3 days of due date, I would like to change the bgcolor of the entry and same for over due items.   Thanks, Stephen  Stephen Cantoriascantoria@msn.com <asp:TemplateField SortExpression="NAME" HeaderText="Name" ItemStyle-Width="120px"> <ItemTemplate> <asp:...

Change cell color in a cell when hyperlink is clicked
I have a table across the bottom of my form, when a user clicks a hyperlink in one of the cells, I want the bgcolor of the cell to change. You can use the onClick event of the cell to change its bgcolor property. For example:<td bgcolor="black" onclick"bgcolor='white';">This is a test!</td>This uses event propogation to capture the click event which is passed down from the link. Steven BeyRecursion: see Recursion Don't know what I'm doing wrong, I used your example and it it doesn't want to cooperate. The bgcolor automatically deafults to the oncli...

Changing the value of one cell when the user changes the value of another cell
I am using a standard GridView with multiple columns and a SQLDataSource. One column is called Qty and another column is called Date. When the user clicks the Edit button and enters a quantity into the Qty column, I would like to automatically fill in today's date into the Date column...before the user clicks Save. Any ideas on how to do that? Thanks in advance, Rick     You would have to make an asych call, check out ASP.NET AJAX: http://ajax.asp.net add a javascript event on the quantity textbox the onchange On the gridviews rowdatabound add this  Protected Sub Gr...

How to change tree view's (web control) back color, font color and font size using CSS (Cascading Style Shteets)
Hi All, I have created tree view (web control) but i want to change all the properties of it, through single style sheet. Like all other controls (label, text box and combo box) it's not possible to change all the properties of treeview through single style sheet by including it to the contol ???? Please help........ MAITRAY. Sorry. No external css. but these attributes: DefaultStyle="background:#CCCCCC;border:solid 1px;color:black;font-size:8pt" HoverStyle="color:blue;font-name:Arial" SelectedStyle="c...

How to change value a Cell in DataTable or Change Display in Gridview ?
Hi, Everyone !I have a issuse in the picture below:   In the Method Bind data To a GridView I have:string b_sdv = "SELECT ma_dvi, ten_dvi FROM DONVI";DataTable dt_dv = (DataTable)BindToTable("b_sdv");string b_snd = "SELECT  ma_dvi, ma_nsd, Ten_nsd FROM NSD;DataTable dt_nsd = (DataTable)BindToTable("b_snd");  // create relationshipDataset ds  = new Dataset()ds.Tables.Add(dt_dv.Copy());ds.Tables.Add(dt_nsd.Copy());DataRelation b_drl = new DataRelation("Relation_Data", ds.Tables["DONVI"].Columns["ma_dvi&qu...

How to change value in cell into DataTable or Change display in the Gridview ?
Hi, Everyone !I have a issuse in the picture below:   In the Method Bind data To a GridView I have:string b_sdv = "SELECT ma_dvi, ten_dvi FROM DONVI";DataTable dt_dv = (DataTable)BindToTable("b_sdv");string b_snd = "SELECT  ma_dvi, ma_nsd, Ten_nsd FROM NSD;DataTable dt_nsd = (DataTable)BindToTable("b_snd");  // create relationshipDataset ds  = new Dataset()ds.Tables.Add(dt_dv.Copy());ds.Tables.Add(dt_nsd.Copy());DataRelation b_drl = new DataRelation("Relation_Data", ds.Tables["DONVI"].Columns["ma_dvi&qu...

Change Datagrid cell color based on cell value
I was wondering if there is a way to change the background color of an individual cell in a datagrid based on it's value. (I code in VB) Example: I have a Due Date field and the cells need to be highlighted yellow for all dates that are over 30 days old. Then for all of the dates that are over 60 days old, their cell backgrounds would need to be red. Thanks for the help in advance Dan Take a look @ Change Color of a Column Based on Column Values In your case you can use <Table> tag and change the <td> background color using helper function HTH Sushila ...

Changing a Cells color based on another cells value
We want to change the color of a previous cell based on the value in the current cell. For example, say we are ranking items as they are read into the datagrid. We have several columns of data we want to rank for first and second place. Once we encounter a value that is greater than the previous high value we would like to change the previous high values cell color to yellow and the new high cells color to green. For example column 1 in the following table would have 12 highlighted in green and 10 highlighted in yellow. See the following table. Column 2 would have 11 highlighted green and th...

Web resources about - Make Gridview cell value a hyperlink and change color of font conditional - asp.net.presentation-controls

Conditional - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

English grammar tenses Test & Use incl. going to, passive voice, time clauses, conditional, if clauses ...
Get English grammar tenses Test & Use incl. going to, passive voice, time clauses, conditional, if clauses, indirect speech on the App Store. ...

All sizes - The Portrait of Conditional Probability, With A Third Ear - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

Yemen government tells UN it agrees to conditional truce
Yemen's government told the UN on Wednesday it would agree to a truce to end more than three months of fighting provided key &quot;guarantees&quot; ...

Weekend Economist: Conditional confidence
The uneven nature of economic growth and volatile investment spending pose serious questions for emerging economic optimism.

Jay Weatherill breaks ranks with conditional backing of 15% GST
South Australia has broken ranks with other Labor states and come out in favour of a 15 per cent goods and services tax, with conditions.

NRL accused of double standards as Balmain Leagues Club gets conditional reprieve
A Balmain Leagues Club director has accused the NRL of double standards after it bailed St George Illawarra out of financial trouble without ...

Liverpool Plains: Barnaby Joyce slams Government's conditional approval for new NSW coal mine
The Federal Agriculture Minister hits out at the Government's decision to give conditional approval for a huge open-cut coal mine near prime ...

Jasper Stam gets 9-month conditional sentence for threats about police
An acquaintance of admitted police murderer Justin Bourque has been given a nine-month conditional sentence for uttering threats about police. ...

Conditional discharge for census resister, 79, found guilty of violating Statistics Act
A 79-year-old Toronto woman has been handed a conditional discharge after being found guilty of violating the Statistics Act for refusing to ...

Resources last updated: 12/14/2015 2:45:04 PM