如前臺(tái)綁定的是label和linkbutton按鈕
protected void LinkBtnDelete_Click(object sender, EventArgs e)
{
//取得當(dāng)前點(diǎn)擊的LinkButton按鈕
LinkButton btn = (LinkButton)sender;
//取得當(dāng)前點(diǎn)擊linkbutton按鈕的所在行
GridViewRow irow = (GridViewRow)btn.NamingContainer;
//在當(dāng)前點(diǎn)擊linkbutton按鈕的行找到label
Label lbltag = (Label)irow.Cells[0].FindControl("Label1");
//將label的值賦值于變量tbtag
string tbtag = lbltag.Text.Trim();
Conndb.Conndb conn = new Conndb.Conndb();
conn.Open();
string[] Sql = new string[1];
Sql[0] = string.Format("delete from News where NewsId={0}", tbtag);
int i = conn.ExeSql(Sql);
if (i == 1)
{
Response.Write("<script>alert('刪除成功');</script>");
this.GridTitle.DataSource = Methed.datasetNew();
this.GridTitle.DataBind();
}
else
{
Response.Write("<script>alert('刪除失敗');</script>");
}
}
如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇