欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Repeater中添加按钮实现点击按钮获取某一行数据的方法

程序员文章站 2024-02-12 22:08:10
本文以一个asp.net程序为例讲述了repeater中添加按钮实现点击按钮获取某一行数据的方法,分享给大家供大家参考借鉴之用。具体步骤如下: 1.添加编辑按钮和删除按钮...

本文以一个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

如下图所示:

Repeater中添加按钮实现点击按钮获取某一行数据的方法

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程序设计有所帮助。