3

我正在研究asp.net custom controlrepeater control用来展示的地方radio buttons。点击时

我需要触发中继器。 我面临的问题不是射击能力,它没有, 和属性。 为了完成 I created , drive i from和 add ,以及其中的属性。 我还在其中添加了一个,以便我可以以编程方式调用它的 click 事件来触发 repeaters 。 现在我面临的问题是我已经触发了事件,但仍然没有触发事件。 知道如何完成这个想法吗?ItemCommand eventRadioButton
RadioButtonItemCommend eventCommendArgumentCommandName

asp.net server controlRadioButtonCommendArgumentCommandName
ButtonbuttonItemCommand event
Button's clickItemCommand

4

1 回答 1

2

您可以在触发单选按钮时调用转发器ItemCommand事件。OnCheckedChanged

我认为主要问题是您不确定如何创建预期的参数ItemCommand,这是一个我相信会有所帮助的示例:

ASPX:

<asp:Repeater ID="rptColors" runat="server" onitemcommand="rptColors_ItemCommand">
    <ItemTemplate>
        <asp:RadioButton ID="rdbColour" Text='<%# Eval("Color") %>' AutoPostBack="true" runat="server" OnCheckedChanged="Checked" /> <br />
    </ItemTemplate>
</asp:Repeater>

后面的代码:

public class Colours
{
    public string Color { get; set; }
}

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            rptColors.DataSource = new List<Colours> { new Colours { Color = "Red" }, new Colours { Color = "Black" } };
            rptColors.DataBind();
        }
    }

    protected void Checked(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in rptColors.Items)
        {
            RadioButton rdbColour = item.FindControl("rdbColour") as RadioButton;
            if (rdbColour.Text.Equals((sender as RadioButton).Text))
            {
                CommandEventArgs commandArgs = new CommandEventArgs("SomeCommand", rdbColour.Text);
                RepeaterCommandEventArgs repeaterArgs = new RepeaterCommandEventArgs(item, rdbColour, commandArgs);
                rptColors_ItemCommand(rdbColour, repeaterArgs);
            }
        }
    }

    protected void rptColors_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        //Runs when you select the radio button in the repeater
        System.Diagnostics.Debugger.Break();
    }
}
于 2013-02-20T08:45:31.090 回答