【问题标题】:asp.net repeater with usercontrol - setting commandargument带有用户控件的 asp.net 中继器 - 设置命令参数
【发布时间】:2011-05-02 18:21:44
【问题描述】:

我有以下中继器代码:

 <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 有关,但我认为两者完全不同,可以分开。

【问题讨论】:

    标签: asp.net user-controls repeater commandargument


    【解决方案1】:

    为什么不获取选定的值,并在 Command 函数中使用它?

    (为什么要尝试将其作为参数发送,从您可以在调用函数的命令中获取它的那一刻起,它是相同的)

    【讨论】:

      【解决方案2】:

      一个有点老的问题,但我自己找到了这个问题的答案。

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

      需要看起来像这样,而不是单引号! asp.net 控件中的所有内联代码都必须以这种方式完成。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        • 2012-09-11
        • 2011-11-27
        • 2022-01-17
        • 2011-02-05
        • 1970-01-01
        • 2015-05-03
        相关资源
        最近更新 更多