我試圖得到確認消息同時點擊上在的GridView刪除按鈕。如果我符合只有該行將被刪除GridView。在CommandField中刪除確認消息?
* .ASPX
<Columns>
<asp:CommandField ButtonType="Button" ShowDeleteButton="true" />
</Columns>
* .ASPX.CS
protected void grdPersTable_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button buttonCommandField = e.Row.Cells[0].Controls[0] as Button;
buttonCommandField.Attributes["onClick"] =
string.Format("return confirm('Are you want delete ')");
}
}
protected void grdPersTable_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lbl0 = (Label)grdPersTable.Rows[e.RowIndex].FindControl("lblId");
txtId.Text = lbl0.Text;
obj.DeleteV(Convert.ToInt32(txtId.Text));
grdPersTable.DataSource = obj.GetTableValues();
grdPersTable.DataBind();
lblMessage.Text = "Deleted successfully !";
}
我使用上面的代碼..我得到錯誤,如「無法投入類型'System.Web.UI.LiteralControl'的對象來鍵入'System.Web.UI.WebControls.Button'。 「 – kasim