Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I create an array of Hyperlinks???

Posted on 2008-06-26
1
Medium Priority
?
1,016 Views
Last Modified: 2013-11-05
I am trying to dynamically create multiple hyperlinks. The count is never the same due to the count of records that are to be displayed.


I get the following error

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 61:         For i = 0 To (myDataSet.Tables(1).Rows.Count - 1)
Line 62:            
Line 63:             PrevApp(i).NavigateUrl = "http://abc.com/WebApp/ave/aveWorkACase.aspx?WACID=" '+ myDataSet.Tables(1).Rows(i).Item(0).ToString
Line 64:             PrevApp(i).Text = myDataSet.Tables(1).Rows(i).Item(0).ToString
Line 65:             PrevAppHolder.Controls.Add(PrevApp(i))
 




Dim PrevApp As HyperLink() = New HyperLink(myDataSet.Tables(1).Rows.Count) {}
 
        
        For i = 0 To (myDataSet.Tables(1).Rows.Count - 1)
            
            PrevApp(i).NavigateUrl = "http://abc.com/WebApp/ave/aveWorkACase.aspx?WACID=" '+ myDataSet.Tables(1).Rows(i).Item(0).ToString
            PrevApp(i).Text = myDataSet.Tables(1).Rows(i).Item(0).ToString
            PrevAppHolder.Controls.Add(PrevApp(i))
            
        Next i

Open in new window

0
Comment
Question by:jrisi03
1 Comment
 
LVL 10

Accepted Solution

by:
orbulat earned 375 total points
ID: 21881766
how about do it in this way?
try not to define the array, instead, you declare a new Hyperlink object in each iteration

(i am not familiar with VB, but u can try to "New" a hyperlink in the for-loop)

 
        
        For i = 0 To (myDataSet.Tables(1).Rows.Count - 1)
            Dim PrevApp As HyperLink() = New HyperLink()
            PrevApp(i).NavigateUrl = "http://abc.com/WebApp/ave/aveWorkACase.aspx?WACID=" '+ myDataSet.Tables(1).Rows(i).Item(0).ToString
            PrevApp(i).Text = myDataSet.Tables(1).Rows(i).Item(0).ToString
            PrevAppHolder.Controls.Add(PrevApp(i))
            
        Next i

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

886 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