2010-10-07 36 views
1

我是asp.net中的新手。我正在嘗試將文本和URL從數據庫加載到超鏈接中。調試後,我發現該值已成功加載到超鏈接控件中,但它不顯示在html代碼中?有誰知道這是怎麼發生的?對不起,我的英語不好。使用後面的代碼無法更改Asp超鏈接的屬性

   If myReader2.Read Then 
          Dim temp_panel As Panel 
          Dim temp_hyperlink As HyperLink         
          temp_panel = FindControlRecursive(Me, "Panel" & i.ToString()) 
          temp_panel.CssClass = "accordionItem"         
          temp_hyperlink = FindControlRecursive(Me, "HyperLink" & (i).ToString()) 
          temp_hyperlink.Text = myReader2("Text") 
          temp_hyperlink.NavigateUrl = myReader2("Link") 
          temp_hyperlink.CssClass = "accordionItem" 
          temp_hyperlink.RenderControl(o) 
          myConn2.Close() 
       End If 

上面是代碼隱藏。

<asp:Panel ID="Panel1" runat="server" class="accordionIteminvisible"><asp:HyperLink ID="HyperLink1" runat="server" /></asp:Panel> 
          <asp:Panel ID="Panel2" runat="server" class="accordionIteminvisible"><asp:HyperLink ID="HyperLink2" runat="server" /></asp:Panel> 
          <asp:Panel ID="Panel3" runat="server" class="accordionIteminvisible"><asp:HyperLink ID="HyperLink3" runat="server" /></asp:Panel> 

以上是asp代碼。

      <div id="ctl00_AccordionPane1_content_Panel1" class="accordionIteminvisible"> 

    </div> 
          <div id="ctl00_AccordionPane1_content_Panel2" class="accordionIteminvisible"> 
     <a id="ctl00_AccordionPane1_content_HyperLink2"></a> 
    </div> 
          <div id="ctl00_AccordionPane1_content_Panel3" class="accordionIteminvisible"> 
     <a id="ctl00_AccordionPane1_content_HyperLink3"></a> 
    </div> 

以上是html代碼。

回答

2

編輯:原來的海報回答了他自己的問題,但標記了這一個答案。 OP的解決方案:

問題是,此頁面是我的母版頁。內容頁面中也有同名的超鏈接。因此,這些設置是在內容頁面上進行的,而不是在母版頁上進行的。在母版頁上更改超鏈接的名稱後,它將起作用。

============================================== ======================

您是否嘗試過調試代碼?當您到達時會發生什麼?

temp_hyperlink.Text = myReader2("Text") 

i的值是多少?

myReader2("Text")的值是多少?

您是否找到連接temp_hyperlink的鏈接?

編輯: 即使html中沒有任何內容,鏈接是否顯示在頁面上? url在讀者中的價值是什麼? 你嘗試過使用asp:linkbutton嗎?

+0

我已經解決了這個問題,謝謝你的回答。 – 2010-10-07 06:39:27

+0

張貼您的答案並將其標記爲答案 – adrianos 2010-10-07 06:40:32

+0

是的,我累了調試它。問題是這個頁面是我的母版頁。內容頁面中也有同名的超鏈接。因此,這些設置是在內容頁面上進行的,而不是在母版頁上進行的。在母版頁上更改超鏈接的名稱後,它將起作用。非常感謝。 – 2010-10-07 06:41:12