記錄一下,主要是這句:
TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;
Repeater真是太強了,太靈活。除了Repeater別的都不用。
復制代碼 代碼如下:
table>
asp:Repeater ID="rptList" runat="server"OnItemCommand="rptList_ItemCommand">
ItemTemplate>
tr>
td>asp:TextBox ID="txtNum" runat="server" Text='%#Eval("ProNum")%>'>/asp:TextBox>/td>
td>asp:Button ID="btnUpdate" runat="server" Text="更新"CommandName="update" CommandArgument='%#Eval("PID") %>' />/td>
/tr>
/ItemTemplate>
/asp:Repeater>
/table>
復制代碼 代碼如下:
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "update":
string arg = e.CommandArgument.ToString();//取得參數
//找到激發事件的行內控件,這個很有用,能將更多需要的參數值傳遞過來。
TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;
//下面執行業務邏輯
string jsStr = "script>alert('刪除成功!" + txtNum.Text + "')/script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", jsStr,false);
break;
}
Bind();
}
您可能感興趣的文章:- Repeater控件與PagedDataSource結合實現分頁功能
- Repeater控件實現編輯、更新、刪除等操作示例代碼
- Repeater怎么實現多行間隔顯示分隔符
- Repeater中嵌套Repeater的示例介紹
- repeater做刪除前彈窗詢問實例
- 給Repeater控件里添加序號的5種才常見方法介紹
- asp.net Repeater 數據綁定的具體實現(圖文詳解)
- Repeater控件綁定的三種方式
- ASP.NET筆記之 Repeater的使用
- asp.net Repeater分頁實例(PageDataSource的使用)
- Repeater里switch的使用方法
- Repeater中添加按鈕實現點擊按鈕獲取某一行數據的方法