开发者

Generate URLs from database code behind

This in ref to this question that i asked but never got answered ASP.NET 4 ACCESS DATA TO APPLY TO NavigateUrl but suppose thats redundant now.

I need to generate dynamic URLs from a database in code behind and then use them in a list view but i cannot find anywhere on the internet or in my book that covers something like this.

Im getting data out using below in a code behind page:

    'portfolio navigation data
    Dim rdrPortfolioNav As SqlDataReader

    Dim cmdPortfolioNav As SqlCommand = New SqlCommand()
    cmdPortfolioNav.CommandText = "SELEC开发者_如何学CT TOP 6 [id], [date], [client], [category], [title], [body], [website], [navimage], [navdesc] FROM [portfolio] ORDER BY [date] DESC"
    cmdPortfolioNav.CommandType = CommandType.Text
    cmdPortfolioNav.Connection = boomSQL

    cmdPortfolioNav.Connection.Open()
    rdrPortfolioNav = cmdPortfolioNav.ExecuteReader(CommandBehavior.CloseConnection)

    lvPortfolioNav.DataSource = rdrPortfolioNav
    lvPortfolioNav.DataBind()

    cmdPortfolioNav.Dispose()

there will be multiple records returned and i need to then concatenate to generate URLs from fields in the data e.g. "portfolio/" & [id] & "/" & [category] & "/" & [title] and then display these in a list view with the concatenated text being the NavigateUrl:

<asp:ListView ID="lvPortfolioNav" runat="server">
                    <ItemTemplate>
                    <div class="work">
                        <asp:HyperLink runat="server" NavigateUrl="" ToolTip=""><span class="title"><%# DataBinder.Eval(Container.DataItem, "title")%></span></asp:HyperLink>
                        <asp:Image runat="server" ImageUrl="<%# DataBinder.Eval(Container.DataItem, &quot;navimage&quot;)%>" AlternateText="<%# DataBinder.Eval(Container.DataItem, &quot;client&quot;)%>" ToolTip="<%# DataBinder.Eval(Container.DataItem, &quot;client&quot;)%>" />
                        <span class="desc"><%# DataBinder.Eval(Container.DataItem, "navdesc")%></span>
                    </div>

                    </ItemTemplate>
                </asp:ListView>

Can anyone help or at least get me started on how to loop through each record on the code behind page to generate all the urls then how to show these on the actual page within the list view.

Much appreciated,

J.


You could update the NavigateUrl property on your HyperLink to something like this:

<asp:HyperLink runat="server" NavigateUrl='<%# String.Format("portfolio/{0}/{1}/{2}", DataBinder.Eval(Container.DataItem, "id"), DataBinder.Eval(Container.DataItem, "category"), DataBinder.Eval(Container.DataItem, "title")) %>' ToolTip="">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜