ItemCommand包含RepeaterCommandEventArgs,它有两个重要的字段:
的CommandName
CommandArgument
如何获取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>
答案 0 :(得分: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" .... >