本文以一個asp.net程序為例講述了Repeater中添加按鈕實現點擊按鈕獲取某一行數據的方法,分享給大家供大家參考借鑒之用。具體步驟如下:
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控件,添加事件函數onitemcommand
如下圖所示:
3.添加函數內容
具體功能代碼如下:
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程序設計有所幫助。
新聞熱點
疑難解答