repeater 删除数据的问题
页面中有个repeater控件。为repeater控件每条记录添加一个linkbutton。当点击每个linkbutton时弹出确认框。询问是否确定删除。点击是后触发删除事件。把对应点击按纽的记录删除。
现在我linkbutton的click事件里写了如下代码
protected void EditLink_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Comments.Controls)
{
LinkButton EditLink =item.FindControl( "EditLink ") as LinkButton;
SqlConnection con = new SqlConnection(SiteSqlServer);
con.Open();
SqlCommand cmd = new SqlCommand( "custom_DeleteLeave ", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( "@PostID ", SqlDbType.Int).Value = EditLink.CommandArgument.ToString();
cmd.ExecuteNonQuery();
con.Close();
}
}
我现在取到linkbutton是所有数据的后的LINKBUTTON都选出来,这样的话,就会把所显示的数据都给删除了。怎么写才能只删除你点击的那行数据呢
我想关键是选取LINKBUTTON的问题,请问如何解决这个问题呢?
------解决方案--------------------前台 :: <asp:Repeater ID= "Repeater1 " runat= "server " OnItemCommand= "Reperter_ItemCommand ">
<asp:Button ID= "Button3 " runat= "server " Text= "Button " CommandName= "Select " CommandArgument= ' <%#DataBinder.Eval(Container.DataItem, "CoID ")%> ' />
后台::
protected void Reperter_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Select ")
{
Response.Write(e.CommandArgument.ToString());
//e.CommandArgument.ToString()就是这一行的主键值,下面接着操作该主键值就好了。。。
}
}
------解决方案-------------------- <asp:Repeater ID= "Repeater1 " runat=