如何取ID
如上图,数据绑定是用的DATALIST,选中任意项,可以进行删除操作。可是绑定的数据没有ID,那如何获取ID呢?我删除的代码如下:
protected void Image1_ServerClick(object sender, ImageClickEventArgs e)
{
for (int i = 0; i < this.DataList1.Controls.Count; i++)
{
CheckBox cbx = this.DataList1.Controls[i].FindControl("CheckBox2") as CheckBox;
if (cbx != null)
{
if (cbx.Checked == true)
{
try
{
SpaceLogic.PairFriendsClass.DeleteData(ID);
this.Page.RegisterStartupScript("", "<script>alert('操作成功!')</script>");
GetLetter();
}
catch
{
this.Page.RegisterStartupScript("", "<script>alert('操作失败!')</script>");
}
}
}
}
}