Repeater中添加按鈕實現(xiàn)點擊按鈕獲取某一行數(shù)據(jù)的方法
更新時間:2014年08月26日 09:04:43 投稿:shichen2014
這篇文章主要介紹了Repeater中添加按鈕實現(xiàn)點擊按鈕獲取某一行數(shù)據(jù)的方法,是非常實用的一個技巧,需要的朋友可以參考下
本文以一個asp.net程序為例講述了Repeater中添加按鈕實現(xiàn)點擊按鈕獲取某一行數(shù)據(jù)的方法,分享給大家供大家參考借鑒之用。具體步驟如下:
1.添加編輯按鈕和刪除按鈕
具體代碼如下:
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand"> <ItemTemplate> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td style="width: 15%;" class="style2"> <%#Eval("E_Name")%> </td> <td> <asp:ImageButton ID="ImageButton1" runat="server" CommandName="JustEdit" ImageUrl="~/icon./edit.gif" CommandArgument=<%#Eval("E_ID")%>/> <asp:ImageButton ID="btn_del" runat="server" CommandName="JustDelete" ImageUrl="~/icon./del.gif" OnClientClick="return confirm('確認刪除?')" CommandArgument=<%#Eval("E_Id")%> /> </td> </tr> </table> </ItemTemplate> </Repeater>
2.選中Repeater控件,添加事件函數(shù)onitemcommand
如下圖所示:
3.添加函數(shù)內(nèi)容
具體功能代碼如下:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { Int32 eid = Convert.ToInt32(e.CommandArgument.ToString());//獲取E_ID的值 if (e.CommandName == "JustDelete") { BLL_Emp bll = new BLL_Emp(); bll.Delete(eid); Server.Transfer("~/emp/Employee.aspx");//刷新 } else if (e.CommandName == "JustEdit") { Response.Redirect("~/emp/UpdateEmployee.aspx?E_Id=" + eid.ToString() + "&C_Id=" + Request.QueryString["C_Id"].ToString()); } }
希望本文所述示例對大家的asp.net程序設計有所幫助。
您可能感興趣的文章:
- 在ASP.NET 2.0中操作數(shù)據(jù)之二十九:用DataList和Repeater來顯示數(shù)據(jù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十:格式化DataList和Repeater的數(shù)據(jù)
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十三:基于DataList和Repeater使用DropDownList過濾的主/從報表
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十四:基于DataList和Repeater跨頁面的主/從報表
- 在ASP.NET 2.0中操作數(shù)據(jù)之三十五:使用Repeater和DataList單頁面實現(xiàn)主/從報表
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十一:DataList和Repeater數(shù)據(jù)分頁
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十二:DataList和Repeater數(shù)據(jù)排序(一)
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十三:DataList和Repeater數(shù)據(jù)排序(二)
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十四:DataList和Repeater數(shù)據(jù)排序(三)
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十五:DataList和Repeater里的自定義Button
相關文章
c# String擴展 讓你在PadLeft和PadRight時不再受單雙字節(jié)問題困擾
這篇文章主要介紹了c# String擴展 讓你在PadLeft和PadRight時不再受單雙字節(jié)問題困擾,需要的朋友可以參考下2020-04-04