c#
  • asp.net
  • 2013-02-19 59 views 0 likes 
    0

    這是我的。加載頁面但超鏈接不是超鏈接。我在瀏覽器中查看頁面的源代碼,並在下面的DataNavigateUrlFormatString屬性中看到href中的相同字符串。我已經嘗試了許多不同的方法,並且在執行期間沒有鏈接或錯誤。如何在asp:HyperLinkField中使用C#變量?

    <asp:HyperLinkField DataNavigateUrlFields="LIDCode" 
    DataNavigateUrlFormatString='<%# Request.ServerVariables["SCRIPT_NAME"] %>?LC={0:d}&DD=true'> 
    </asp:HyperLinkField> 
    
    +0

    由於某種原因,我的這裏是我的代碼沒有顯示出來。在這裏它又是... 2013-02-19 17:01:16

    回答

    0

    如果DataNavigateUrlFormatString是給我麻煩,因爲我不能嵌入其他服務器標籤(這是問題)的屬性裏面內嵌服務器標籤,我該做什麼設置在該DataNavigateUrlFormatString財產後面的代碼,例如在Page_Load事件

    private void Page_Load() 
    { 
        if (!IsPostBack) 
        { 
    
         string strUrlFormat = Request.ServerVariables["SCRIPT_NAME"] + "?LC={0:d}&DD=true" 
         // get the gridview object and set the DataNavigateUrlFormatString property for the column in question here... so if you gridview ID = "myGridView" and it is the third column... 
         myGridView.Columns[2].DataNavigateUrlFormatString = strUtlFormat; 
    
        } 
    } 
    
    0

    嘗試這樣的事情,而不是: - 創建公共靜態方法GetLink() - 更新代碼就像超級鏈接看起來像這樣

    DataNavigateUrlFormatString='<%# PageName.GetLink() %>' 
    
    public static string GetLink() 
    { 
        //needs to be completed but you see the point 
        return HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]; 
    } 
    
    相關問題