尝试这个
HTML标记
下面是APS.Net GridView控件的HTML标记。这里我使用CommandField和OnRowDeleting事件来删除GridView Row。因此,我会将JavaScript确认框应用到CommandFieldDelete按钮本身。
<asp:GridView ID="GridView1" CssClass = "Grid" runat="server" OnRowDeleting="OnRowDeleting" AutoGenerateColumns = "false" OnRowDataBound = "OnRowDataBound">
<Columns>
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
</Columns>
</asp:GridView>
运用JavaScript的确认框到GridView CommandField中 删除按钮
要应用的JavaScript确认框,我正在寻找,因为在GridView细胞指数2的控制按钮它有CommandField。一旦
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string item = e.Row.Cells[0].Text;
foreach (Button button in e.Row.Cells[2].Controls.OfType<Button>())
{
if (button.CommandName == "Delete")
{
button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ return false; };";
}
}
}
}
使用CommandField中和OnRowDeleting 事件
下面是代码的ASP.Net的GridView行使用OnRowDeleting事件删除删除ASP.Net的GridView行
protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
DataTable dt = ViewState["dt"] as DataTable;
dt.Rows[index].Delete();
ViewState["dt"] = dt;
BindGrid();
}
你必须做出动态的数据表格来存储gridview中的值,这是否太需要一些代码来解释... –
http:// dotprogramming .blogspot.com/2013/10/how-to-delete-multiple-rows-from.html –
http://www.codeproject.com/Questions/267426/how-to-delete-the-gridview-row-with -templatefield –