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 }

 

控件還是比較好理解~~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM