0

ItemCommand 包含 RepeaterCommandEventArgs 有两个重要字段:

命令名

命令参数

如何获取 Button 事件,获取 asp:DropDownList 选择值

<asp:FormView runat="server" id="fwHotelDetails" DataKeyNames="id" OnDataBound="fwHotelDetails_DataBound" OnModeChanging="fwHotelDetails_ModeChanging" >
    <ItemTemplate>
         <asp:Repeater runat="server" id="repScore">
          <ItemTemplate>
            <asp:DropDownList ID="ddlnumber" runat="server">
                                                    <asp:ListItem>1</asp:ListItem>
                                                    <asp:ListItem>2</asp:ListItem>
                                                    <asp:ListItem>3</asp:ListItem>
                                                </asp:DropDownList>

            <asp:LinkButton ID="saveButton" runat="server" CausesValidation="False" CommandName="Edit" CommandArgument='<%# Eval("id")%>' Text="Edit" />
          </ItemTemplate>
        </asp:Repeater>

        <EditItemTemplate>
             Test test, anything??
        </EditItemTemplate>

    </ItemTemplate>
</asp:FormView>
4

1 回答 1

0

RepeaterCommandEventArgs参数包含一个名为 的属性Item。您可以从此属性访问方法FindControl()

所以你的代码看起来像这样:

void repScore_ItemCommand(Object sender, RepeaterCommandEventArgs e) { 
   DropDownList ddl = (DropDownList)e.Item.FindControl("ddlNumber");
   string selectedValue = ddl.SelectedValue;
}

另外,不要忘记连接中继器来处理事件:

<asp:Repeater ... OnItemCommand="repScore_ItemCommand" .... >
于 2013-02-26T19:09:37.863 回答