user3204853
user3204853

Reputation: 5

I want to be able to link to the pages in the object

I have an asp page and in the code behiend I have the following for loop:

 For Each objDep In objWO.FillInfo.Dependency
        lblSO.Text &= objDep.DocNo.ToString() & ", "

 Next

What I want to be able to do is make each objDep a link. Is this possible in the code behind or is there a better way? Sorry very new to ASP.NET.

Upvotes: 0

Views: 22

Answers (1)

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107586

Yes, you can. A few different ways. One option would be to change the type of your lblSO control from a Label to a Literal (<asp:Literal ID="lblSO" runat="server" />) and then append hyperlinks to it:

lblSO.Text = String.Join(", ", objWO.FillInfo.Dependency _
    .Select(Function(dep) String.Format("<a href=""Link.aspx?No={0}"">{0}</a>", _
        dep.DocNo)).ToArray())

Another way, perhaps the "ASP.NET way," is to use a Repeater, and the list of dependencies as a data source:

<asp:Repeater ID="rptDependencies" runat="server">
    <ItemTemplate>
        <asp:Hyperlink ID="lnkDependency" runat="server"
            Text='<%# Eval("DocNo") %>'
            NavigateUrl='<%# String.Format("~/Link.aspx?DocNo={0}", Eval("DocNo")) %>' />
    </ItemTemplate>
    <SeparatorTemplate>, </SeparatorTemplate>
<asp:Repeater>

And then in your code-behind you bind your objects to the list:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim objWO = '...
    If Not Page.IsPostBack Then
        rptDependencies.DataSource = objWO.FillInfo.Dependency
        rtpDependencies.DataBind()
    End If
End Sub

Upvotes: 3

Related Questions