手机
当前位置:查字典教程网 >编程开发 >C#教程 >Repeater中添加按钮实现点击按钮获取某一行数据的方法
Repeater中添加按钮实现点击按钮获取某一行数据的方法
摘要:本文以一个asp.net程序为例讲述了Repeater中添加按钮实现点击按钮获取某一行数据的方法,分享给大家供大家参考借鉴之用。具体步骤如下...

本文以一个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> <%#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中添加按钮实现点击按钮获取某一行数据的方法1

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" + eid.ToString() + "&C_Id=" + Request.QueryString["C_Id"].ToString()); } }

希望本文所述示例对大家的asp.net程序设计有所帮助。

【Repeater中添加按钮实现点击按钮获取某一行数据的方法】相关文章:

C# SkinEngine控件 给窗体添加皮肤的方法

HTML文本框的值改变后触发后台代码的方法

c# 给button添加不规则的图片以及用pictureBox替代button响应点击事件的方法

C#中实现网段扫描的代码

C#TreeView 无限级别分类实现方法

c# 获取数据库中所有表名称的方法

解析c#在未出现异常情况下查看当前调用堆栈的解决方法

C#计算代码执行时间的方法

使用checked语句防止数据溢出的解决方法

C#编程实现Excel文档中搜索文本内容的方法及思路

精品推荐
分类导航