2010-10-30 36 views
1

我有以下中繼代碼:與用戶控件asp.net中繼器 - 設置commandargument

<asp:Repeater ID="repMain" runat="server" OnItemCommand="repMain_ItemCommand" EnableViewState="false"> 
    <ItemTemplate> 
    <dmg:testcontrol runat="server" MyData=<%#Container.DataItem %>> 


    </dmg:testcontrol> 
    </ItemTemplate> 
    </asp:Repeater> 

的用戶控件系統testControl看起來像:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="TestRepeater.TestControl" %> 
<asp:Literal runat="server" ID="litMain" Text="<%#MyData.MyValue %>"></asp:Literal> 
<asp:DropDownList runat="server" ID="dropdownMain"></asp:DropDownList> 
<asp:Button runat="server" ID="btnMain" Text="Click Me" CommandName="Update" CommandArgument="<%#dropdownMain.SelectedValue%>"/> 

是否有可能對我來說,通過dropdownMain發送。 SelectedValue作爲CommandArgument?

剛纔它是一個空字符串。

感謝

鄧肯

PS這是關係到ASP.NET Repeater not binding after ItemCommand,但我認爲這兩個十分不同,保持分開。

回答

1

有點老問題,但我只是我自己找到了答案,這一個。

CommandArgument="<%#dropdownMain.SelectedValue%>" 

需要看起來像這樣,而不是單引號!所有內聯代碼必須以這種方式完成。

CommandArgument='<%#dropdownMain.SelectedValue%>' 
0

爲什麼不能獲得選定的值,並在Command函數中使用它?

(爲什麼要嘗試把它發送作爲參數,從時刻,你可以得到它的命令調用函數內部及其同)