这是我的网格视图
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
OnRowDeleting="GridView1_RowDeleting"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="name" HeaderText="name" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btn1" Text="edit" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="Edit" ></asp:LinkButton>
<asp:LinkButton ID="Button1" Text="delete" runat="server" CommandArgument='<%#Eval("id") %>' CommandName="Delete" OnClientClick=' return confirm("do you want to delete")' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是函数调用
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
Response.Write(e.CommandArgument.ToString());
if (e.CommandName == "Delete")
{
//Response.Write(e.CommandArgument);
MySqlConnection conn = new MySqlConnection(connectionString);
conn.Open();
string query = "delete from brand where id='" + e.CommandArgument + "'";
MySqlCommand cmd = new MySqlCommand(query,conn);
cmd.ExecuteNonQuery();
conn.Close();
fillgrid();
}
}
onrowcommand
不会被解雇。为什么?