[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Evaluate items in datalist in asp.net

Posted on 2013-01-29
5
Medium Priority
?
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 800 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 1200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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