2012-01-28 42 views
1

我創建了位於Repeater Control中的LinkBut​​ton。 CategoryID是LinkBut​​ton控件中的一個變量,必須在Repeater控件綁定到數據後獲取值。但是CategoryID始終爲零。爲什麼鏈接按鈕控制變量沒有得到任何值?

我有以下的ASP和C#代碼:背後

<asp:Repeater ID="rpt1" runat="server" 
      OnItemDataBound="rpt1_ItemDataBound" 
      OnItemCommand="rpt1_ItemCommand">  
    <ItemTemplate> 
     <div> 
     <%# Eval("Name") %>-<%# Eval("CollectionType")%> 
     <asp:LinkButton ID="LinkButton1" runat="server" Text="[edit item]" 
      PostBackUrl='AddItem.aspx?CategoryID=<%# Eval("CollectionID")%>' /> 
     </div>  
    </ItemTemplate> 
</asp:Repeater> 

代碼:

public void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     List<GlassesCollection> gc = BL.GetDataBL.GetCollection(); 
     rpt1.DataSource = gc; 
     rpt1.DataBind(); 
    } 
} 

任何想法,爲什麼類別ID變量沒有得到任何價值,我怎樣才能解決這個問題?

+2

做了'GlassesCollection'對象有一個'CollectionID'屬性定義?它總是設置? – Oded 2012-01-28 23:05:45

+0

你可以看到(並在此輸入)html頁面上呈現什麼? – Aristos 2012-01-29 00:09:28

+0

Oded,在GlassesCollection對象中定義的CollectionID屬性。 – Michael 2012-01-29 00:25:07

回答

1

服務器控制參數不能包含文字文本和計算表達式的混合。 你的代碼將會直接發送回AddItem.aspx?CategoryID = <%#Eval(「CollectionID」)%>並且它不會評估尖括號內的代碼。

您需要更改參數,像這樣

PostBackUrl='<%# "AddItem.aspx?CategoryID=" + Eval("CollectionID")%>' />