2012-03-15 27 views
2

我想自動設置一個asp:標籤的文本到一個url參數,但它似乎不工作。獲取一個URL參數到asp.net標籤

這是我的代碼:

 <asp:Label ID="lblHouse" runat="server" 
     Text='<%# Request.QueryString["Selection"] %>' 
     Font-Bold="True" 
     Font-Size="Large"></asp:Label> <br /> <br /> 

我在做什麼錯?

感謝您的幫助。

回答

4

您可以使用<%=%>(而不是<%#),並把它的ASP內部:標貼標籤,而不是Text屬性:當你的數據對象綁定

  <asp:Label ID="lblHouse" runat="server" 
      Font-Bold="True" 
      Font-Size="Large"><%= Server.HTMLEncode(Request.QueryString["Selection"]) %></asp:Label> 
+0

ahhh美麗的我知道我錯過了一些東西。非常感謝您的幫助。 – 2012-03-15 18:11:11

+0

有關其他選項的更多信息,請參閱:http://stackoverflow.com/questions/8738122/server-tags-cannot-contain-constructs – Khan 2012-03-15 18:13:23

+0

使用Selection = Aristos 2012-03-15 18:48:39

-1

您可以在代碼中設置文本後面的文件

lblHouse.Text = Request.QueryString("Selection").ToString 
+0

是的,我知道後面的代碼,但我想知道如果有一種方法在aspx頁面中完成它。 – 2012-03-15 18:02:53

0
<%# ... %> 

evaulates。

嘗試

lblHouse.DataBind() 

,或者嘗試使用

<%= ... %> 
+0

「<%= ... %>」將不起作用,它會拋出異常或返回任何內容,具體取決於您的「和」用途。 – Khan 2012-03-15 18:11:13

3

嘿試試這個它的做工精細

<asp:Label ID="lblHouse" runat="server"   
     Font-Bold="True" 
     Font-Size="Large"><%= Request.QueryString["Selection"] %></asp:Label>