Solved

Evaluate items in datalist in asp.net

Posted on 2013-01-29
5
330 Views
Last Modified: 2013-01-30
I have a datalist and the last item of the list is a link, but I want to make sure the file exists it is supposed to be linking to before doing the link.  How do I evaluate the items seperately?

This is the code I attempted, it does not link to anything.

 <itemtemplate>
                    <td valign="top" width="14%" align="left">
                        <asp:Label ID="lblStatus" runat="server" text='<%# Eval("Status") %>'/>
                    </td>
                    <td valign="top" width="14%" align="left">
                        <asp:Label ID="lblStatementNumber" runat="server" text='<%# Eval("StatementNumber") %>' />
                    </td> 
                   
                    <td valign="top" width="14%" align="left">
                        <asp:Label ID="lblStatementDate" runat="server" text='<%# Eval("StatementDate") %>' />
                    </td>
                    <td valign="top" width="14%" align="left">
                        <asp:Label ID="lblDueDate" runat="server" text='<%# Eval("DueDate") %>'/>
                    </td>
                    <td valign="top" width="14%" align="left">
                        <asp:Label ID="lblBilledAMT" runat="server" text='<%# Eval("BilledAMT") %>'/>
                    </td>
                    <td valign="top" width="14%" align="left">
                        <asp:Label ID="lblOutstandingAMT" runat="server" text='<%# Eval("OutstandingAMT") %>' />
                    </td>
                    <td valign="top" width="14%" align="left">
                        <asp:HyperLink ID="HyperLink1" runat="server" Text="PDF" ImageUrl="~/Images/pdficon_small.gif" Target="_blank"
                        navigateurl = '<% if (My.Computer.FileSystem.FileExists("\\172.16.2.12\Statements\"Eval("StatementNumber")) _
                                then "https://secure.a2gov.org/epayments/statements/" & Eval("StatementNumber") & ".pdf"
                        
                        
                        end if
                        %>'
                        
                        
                         />
                        <asp:HyperLink ID="lnkFormat" runat="server" Text="PDF" ImageUrl="~/Images/pdficon_small.gif" Target="_blank" />
                    </td>
                </itemtemplate>

Open in new window

0
Comment
Question by:UnderSeven
  • 2
  • 2
5 Comments
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 200 total points
ID: 38831761
You can use the DataList.ItemDataBound event to add this logic.

Your line

'<% if (My.Computer.FileSystem.FileExists("\\172.16.2.12\Statements\"Eval("StatementNumber"))

is missing a &

'<% if (My.Computer.FileSystem.FileExists("\\172.16.2.12\Statements\"Eval("StatementNumber"))
0
 

Author Comment

by:UnderSeven
ID: 38833048
This event you mentioned, is there an event I could use for a link on a datalist clicked?

So for instance, removing the part of the code that does logic on the aspx side, could I use an event for that link clicked that then used the datalist.itemdatabound to determine which one it was one when clicked "statementnumber" and then do all of the work in the code behind?  

Could you point me in the right direction?  I prefer to do this in the code behind.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38833089
Yes you can. In the ItemDataBound event, subscribe to the LinkClicked event of the link and you can handle it in code behind.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 300 total points
ID: 38833116
Here's how you can get your link and statement number in the ItemDataBound event.

Protected Sub DataList1_ItemDataBound(sender As Object, e As DataListItemEventArgs) Handles DataList1.ItemDataBound
	If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
		Dim drow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
		Dim hl As HyperLink = DirectCast(e.Item.FindControl("HyperLink1"), HyperLink)
			'You have link and statement number.
			'Manipulate them as you like
		Dim sn As String = drow("StatementNumber").ToString()
	End If
End Sub

Open in new window

0
 

Author Closing Comment

by:UnderSeven
ID: 38835612
These solutions were really quite cool.  I didn't quite grasp the power of the itemdatabound event until guru_sami's response, or I might not of asked about on click.  You both answered my questions, and I'm thrilled to understand this functionality better.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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