asp.net中继器与用户控件 - 设置commandargument
-
27-09-2019 - |
题
我有以下中继器代码:
<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送?
刚才它是一个空字符串。
由于
邓肯
解决方案
有点老问题,但我只是我自己找到了答案,这一个。
CommandArgument="<%#dropdownMain.SelectedValue%>"
需要看起来像这样,而不是单引号!一个asp.net控制之内的所有内联代码必须完成这种方式来代替。
CommandArgument='<%#dropdownMain.SelectedValue%>'
其他提示
为什么不给选定的值,并使用它的命令函数里面?
(为什么要尝试把它发送作为参数,从时刻,你可以得到它的命令调用函数内部及其同)
不隶属于 StackOverflow