Repeater 中 OnItemCommand 用法

 1 <table>
 2     <asp:Repeater ID="rptList" runat="server"OnItemCommand="rptList_ItemCommand">
 3     <ItemTemplate>
 4 <tr>
 5     <td><asp:TextBox ID="txtNum" runat="server" Text='<%#Eval("ProNum")%>'></asp:TextBox></td>
 6     <td><asp:Button ID="btnUpdate" runat="server" Text="更新"CommandName="update" CommandArgument='<%#Eval("PID") %>' /></td>
 7 </tr>
 8     </ItemTemplate>
 9     </asp:Repeater>
10 </table>
 1 protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
 2 {
 3     switch (e.CommandName)
 4      {
 5         case "update":
 6             string arg = e.CommandArgument.ToString();//取得参数
 7             //找到激发事件的行内控件,这个很有用,能将更多需要的参数值传递过来。
 8              TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;
 9 
10             //下面执行业务逻辑
11             string jsStr = "<script>alert('删除成功!" + txtNum.Text + "')</script>";
12              Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", jsStr,false);
13             break;
14      }
15 
16 }

控件还是比较好理解~~

原文地址:https://www.cnblogs.com/moy-1313133/p/6933531.html