DNN: EditURL

Posted on 2006-02-13 08:53  深渊呓语  阅读(372)  评论(0)    收藏  举报


EditURL(Byval KeyName as String, Byval KeyValue as String, Byval ControlKey as String)

Return the URL of a Control and the KeyName/KeyValue will be a parameter which can be retrive by Request.QueryString("...")

I had a Datalist which contain a HyperLink control, and I need to set the 'NavigateURL' property of this HyperLink control by EditURL function. So I tried to set it in HTML like:

<asp:HyperLink ID="Link1" runat="server" NavigateURL='<%# EditURL("ItemID", DataBinder.Eval(Container.DataItem, "ID"), "SomePage")'></asp:HyperLink>

But I got an error and this control can not be loaded. I checked the error message, I thought DataBinder.Eval will return an object not String as the function expected, but I don't know how to convert it to a string, so I handle the ItemDataBound event of DataList:


Private Sub ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles myList.ItemDataBound
   If e.Item.FindControl("Link1") Is Nothing Then Exit Sub
   With CType(e.Item.FindControl("Link1"), HyperLink)
       .NavigateUrl = EditUrl("ItemID", DataBinder.Eval(e.Item.DataItem, "ID").ToString(), "SomePage")
   End With
End Sub

It's clear that every module should have a control with empty key.

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3