GridView - If statement for hyperlink or no hyperlink within data presentation

Lets say my data is this in the DB -

Column 1     Column 2          Column 3       Column 4        Column5
date         <description>            $5                INV                 65
date          <description>          -$10
date           <description>           $20             INV                 66

What I what to do is this -

Display the information in a GridView. If INV is present then hyperlink description to 65.pdf. If there is no INV just display everything with no link. 

Basically within the <asp:gridview> code I will need some sort of IF statement for IF Column4='INV' Then

boundfield for Date
hyperlinkfield for column2 linked to column5.pdf
boundfield for column3

Else

All boundfields for Data, column2, and column3

Any help would be great.

0
mxfrail
8/25/2008 6:09:08 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

11 Replies
1100 Views

Similar Articles

[PageSpeed] 45

How about doing something like this? 

<asp:templatefield>
	<itemtemplate>
		<asp:hyperlink id="HyperLink1" runat="server" navigateurl="65.pdf" visible='<%# Eval("Column4").ToString().Equals("INV") %>'
			text="Click Here" />
	</itemtemplate>
</asp:templatefield>

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
8/25/2008 6:35:48 PM

Without playing with that ... does the visible link work like this -

 If true = show a link

If false = display text with no link?

0
mxfrail
8/25/2008 6:48:45 PM

No, if you still want to show the text even if the HyperLink is not displayed, then do something like this instead: 

<asp:templatefield>
	<itemtemplate>
		<asp:hyperlink id="HyperLink1" runat="server" navigateurl="65.pdf" text="Click Here"
			visible='<%# Eval("Column4").ToString().Equals("INV") %>' />
		<asp:label id="Label1" runat="server" text="Click Here" visible='<%# !Eval("Column4").ToString().Equals("INV") %>' />
	</itemtemplate>
</asp:templatefield>

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
8/25/2008 7:16:10 PM

I need to finalize my views and stored procedure but I will test out a variation of this and let you know what happens.

0
mxfrail
8/25/2008 8:08:35 PM

Ok I am kinda confused -

Here is 1 Row of Data with the column Titles

Date - 2007-01-16
ClientID - 2 
Amount - 1506.00 
Transaction - REF#1 -  Advertising Services Due:  for Mailing: Week 1   (Zones: 1) 
Type - INV 
Invoiceno - 1

How it is displayed in a basic gridview as we speak -

                        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2"
                            Visible="False" AllowPaging="True" Width="529px" PageSize="40">
                            <Columns>
                                <asp:BoundField DataField="Date" HeaderText="Date" ReadOnly="True" SortExpression="Date">
                                    <ItemStyle Font-Size="Smaller" />
                                </asp:BoundField>
                                <asp:BoundField DataField="Transaction" HeaderText="Transaction" ReadOnly="True"
                                    SortExpression="Transaction">
                                    <ItemStyle Font-Size="Smaller" />
                                </asp:BoundField>
                                <asp:BoundField DataField="Amount" HeaderText="Amount" ReadOnly="True" SortExpression="Amount">
                                    <ItemStyle Font-Size="Smaller" />
                                </asp:BoundField>
                            </Columns>
                        </asp:GridView>


What I want to happen is this -

Date, Transaction and amount are displayed.

If Type = INV then transaction needs a link to Invoiceno.pdf
If Type != INV just list transaction with no link.

The data is a union select of data for INV, BB, NSF etc. Displaying all account activity for a client. If its an INV there is an associated Invoice we are linking too.

Thanks

0
mxfrail
8/26/2008 6:15:51 PM

Just trying to push this back up so its not lost.

0
mxfrail
8/27/2008 1:59:59 PM

This is where I am at with this. I get some errors -

                                <asp:templatefield>
	                                <itemtemplate>
		                                <asp:hyperlink id="HyperLink1" runat="server" navigateurl="<%# Eval("invoiceno") %>.pdf" text="<%# Eval("transaction") %>"
			                            visible="<%# Eval("Type").ToString().Equals("INV") %>" />
		                                <asp:label id="Label1" runat="server" text="<%# Eval("transaction") %>" visible="<%# !Eval("Type").ToString().Equals("INV") %>" />
	                            </itemtemplate>
                                </asp:templatefield>
2 server tag is not well formed.

and 1 Error 3 Leading '.' or '!' can only appear inside a 'With' statement. C:\Asp.Net\WebSite1\Default.aspx 1 1 C:\Asp.Net\WebSite1\

Which references the top of my page?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>


 

0
mxfrail
8/27/2008 2:41:45 PM

This is what you want then for VB.Net: 

<asp:templatefield>
	<itemtemplate>
		<asp:hyperlink id="HyperLink1" runat="server" navigateurl="<%# Eval("invoiceno") %>.pdf"
			text="<%# Eval("transaction") %>" visible="<%# Eval("Type").ToString().Equals("INV") %>" />
		<asp:label id="Label1" runat="server" text="<%# Eval("transaction") %>" visible="<%# Eval("Type").ToString() <> "INV" %>" />
	</itemtemplate>
</asp:templatefield>

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
8/27/2008 3:02:34 PM

I still get error server tag not well formed for the -

 

  <asp:hyperlink id="HyperLink1" runat="server" navigateurl="<%# Eval("invoiceno") %>.pdf" text="<%# Eval("transaction") %>" visible="<%# Eval("Type").ToString().Equals("INV") %>" />

and

  <asp:label id="Label1" runat="server" text="<%# Eval("transaction") %>" visible="<%# Eval("Type").ToString() <> "INV" %>" />

 lines.

 

 

0
mxfrail
8/27/2008 3:09:40 PM

How about this? 

<asp:templatefield>
	<itemtemplate>
		<asp:hyperlink id="HyperLink1" runat="server" navigateurl='<%# Eval("invoiceno", "{0}.pdf") %>'
			text='<%# Eval("transaction") %>' visible='<%# Eval("Type").ToString().Equals("INV") %>' />
		<asp:label id="Label1" runat="server" text='<%# Eval("transaction") %>' visible='<%# Eval("Type").ToString() <> "INV" %>' />
	</itemtemplate>
</asp:templatefield>

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
8/27/2008 3:17:36 PM

Absolutely perfect!

you are a life saver!

0
mxfrail
8/27/2008 3:34:14 PM
Reply:

Similar Artilces:

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Theming the ControlStyle for BoundField controls within data presentation controls.
Hi all, I was wondering if you can set a default width for template fields and/or BoundField controls within a GridView or  DetailsView / FormView controls? I can change the control widths of bound data control fields, including template fields, by setting the ControlStyle. But if I have a bunch of fields in a DetailsView control for example, it's a pain to have to set the ControlStyle property for each field. I would like to do it in one fell swoop. If I add the following to my skin file, then I get server control rendering errors on my pages. The controls can't be rendered becuase I...

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

Is there any way to control the width of the Gridcolumn when the data is present and not present
I would like to know if there is any way you can control the gridview column width. Thanks in advance. Digish Hi,   try these link http://www.eggheadcafe.com/community/aspnet/17/10004157/setting-gridview-column-w.aspx http://msdn.microsoft.com/en-us/library/ms178296(VS.80).aspxBabaIf this post was useful to you, please Don't forget to click "Mark as Answer". Thanks You.:-)...

Unable to resolve data-bound fields in the NavigateUrl property of a HyperLink control within a Repeater Control
I am attempting to use a data-bound HyperLink control within a Repeater control, but I'm having trouble resolving the data-bound values in the NavigateUrl property.  <asp:HyperLink ID="NameHyperLink" runat="server" Text='<%# Eval("Name") %>' NavigateUrl='~/CoachProfile.aspx?ID=<%# Eval("TeamID") %>&CoachID=<%# Eval("TeamMgmtID") %>' Font-Bold="true">HyperLink</asp:HyperLink>The Text property of the HyperLink control, which is also data-bound, works properly and displays the ...

How to get the data in GridView as hyperlinks in C#.Net
Hi, I am working on the GridView in c#.Net. I want to make the data that is being populated in the GridView as hyperlink.The data is the form of integer. I  dont want to add extra hyperlink column in the GridView. Can any one help me in this regards..?Kindly mail me at mailsazmat@gmail.com ASAP..        You can do something like this<asp:HyperLink Text='<%#Eval("fieldname")%>' Target="_blank" Runat="Server" NavigateUrl='<%# "someurl" & Eval("field2") %>'/> Rega...

How do the different data presentation controls equate in ADO.net?
How does Visual Studio create ado.net equivalents of the datagrid's and gridview's columns and rows?  I am assuming they make a DataRow for each of the rows.  Am I on the right track with this?Is the table created by gridview basically a dataset from ADO.net?  Can anyone offer any guidance with this?Thanks to everyone that has ever helped me with any posts. Hi newbie2C#, The row in datagrid is called DataGridItem and in gridview is called GridViewRow. They are all inherits TableRow Class. DataRow is only one kind of row in GridView control. There are many other t...

presenting XML/XSLT data within a Web control
How do I redirect Code generated by XSL transform of an XML document to a Web control? The Response.Write writes it to the entire screen , not a particular web controlA man's gift maketh room for him, and bringeth him before great men. -- Proverbs 18:16 Use the asp:Xml control.Kirk Allen Evans [MSFT]...

Data presentation without a data control
The Gridview and Formview controls provide good functionality in some circumstances but are clumsey in others. As a newbie to .NET I was wondering if its appropriate to do databinding with textboxes and other data controls outside of one of the new data controls (formview, gridview, etc). Or is it a new standard to always use one of the new data controls. If the answer is yes, would you still use an SQLDatasource, or would you set up the connection in code? And, how would you deal with the syntax? In the Formview we have: <asp:TextBox ID="fnameTextBox" runat="server" ...

ajax control in data presentation controls
can i add ajax controls (MaskedEdit) to presentation controls (dataGrid, dataForm)?? Hi,of course. But keep in mind that those controls are extenders, so you append them to an existing control. Just convert your GridView / DetailsView-fields into templated fields and add the extender you'd like to use to the controls.RegardsMarco Buerckel Don't forget to mark posts that were helpful as answers. Actually, if you looked at the source code for the Masked Edit Extender, you'd see  [TargetControlType(typeof(TextBox))]Meaning, targeting any control type other than textboxes...

detailsview and gridview together
I have a gridview and a details view.  When I select a row in the gridview, i rebind my detailsview usign the id of the row in the grid.  This works great.  Within the detailsview, i have a hyperlink field that i want to use the id of the row in teh grid that was selected.  I want to do this from the gridview_selectedindexchanged event.  How can I get at this hyperlink field and do I do it before calling databind on the detailsview ?  maybe you can temporarily store the index in viewstate likeViewState["CurrentIndex"] = x;and in your detailsview, sim...

Detailed data about GridView and other Data presentation tools!
HiDoes anyone have a link or article that talks about the Gridview and other data presentation tools in-depth, by which I mean providing more data than merely Gridview.DataBind, .Source...etc. I need to learn more about these controls apart from conventional programming techniques.Thanks Karthik MuthuswamyProgrammer AnalystChennai In the Data Tutorials section of this site, they are all explained. ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Blog||Dub@i.net Thanks a lot for that link. Will make the best use of it!!!Karthik MuthuswamyProgrammer An...

Data Presentation Controls and complex data+logic
I'd like to know how people solve problem of binding complex data to data presentation controls. As we all know, real life is not as simple as webcasts etc. assume.Lets say we have something like this.List<Person> liPerson = PersonFactory.GetAllPersons();List<Company> liCompany = CompanyFactory.GetAllCompany();And I want a table something like this:Microsoft      Bill      JohnIBM      Ted      CharlesNokia      Matti Is there a generic solution to...

data presentation controls (how to call the individual controls)
Hi please help me.,i have this question., example i create a site with one control, like textbox. when i double click on the white page, the page load event, in the intellisense, the textbox is visible, but when a formview with a textbox inside, in the same page load event, intellisense, the textbox is not available. how can i do the simple intellisense calling where the textbox is just outside a data presentation control like formview. i mean by this intellisense calling is in VB code view., thanks JFRBPH12™  The textbox is within the formview then you can find it like this...

Web resources about - GridView - If statement for hyperlink or no hyperlink within data presentation - asp.net.presentation-controls

Glamour (presentation) - Wikipedia, the free encyclopedia
Today, glamour is the impression of attraction or fascination that a particularly luxurious or elegant appearance creates, an impression which ...

authorSTREAM App Brings PowerPoint Presentations To Facebook
PowerPoint presentations aren’t just for conference rooms anymore, as Facebook application authorSTREAM allows users to upload presentations ...

Facebook careers: ecosystem measurement manager, security program manager, presentation designer, more ...
... Other noteworthy jobs include a vertical client partner focused on fast-moving consumer goods, a manager of ecosystem measurement and a presentation ...

Lessonator: Create music slideshow presentations
Lessonator is a tool for creating beautiful music slideshow presentations on your Mac. It works like a mashup between Apple’s Keynote and Garageband, ...

Scripting News: Create a presentation in Fargo.
... move my whole act over there, but in the meantime, here's a pointer to my latest piece. http://dave.smallpict.com/2013/06/28/howToCreateAPresentationInFargo ...

How to Make a Powerful Sales Presentation
... about it? Using the simple C.F.B.I. model will help you do just that.After going through the B-CHUBS Needs How to Make a Powerful Sales Presentation ...

Presentation Skills - Körpersprache for iPhone, iPod touch, and iPad on the iTunes App Store
Get Presentation Skills - Körpersprache on the App Store. See screenshots and ratings, and read customer reviews.

Chrome Beta v48 adds custom notification buttons, Presentation API support and more
... it some notable changes that will make developers' jobs much easier. New in the Chrome Beta version 48 update is support for the handy Presentation ...

Football Manager 2016 review: Presentation makes perfect
At one point it was all going smoothly. Inspired by Jurgen Klopp, my Liverpool team was playing a high-pressure, high-tempo game that even the ...

PowerPoint Presentation of the Darned
... PowerPoint deck from Jeb’s recent “Imma Tell My Mom, Dad and Big Brother You Were MEAN to Me” conference. There are 112 slides in the presentation. ...

Resources last updated: 12/26/2015 3:13:07 AM