日期:2014-05-17 浏览次数:20382 次
<asp:TemplateField ShowHeader="False" HeaderText="删除"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="del" OnClientClick="javascript:return confirm('确定删除吗?')" Text="删除"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = int.Parse(e.CommandArgument.ToString());//调试,到这里出错,输入字符串的格式不正确 int id = int.Parse(this.GridView1.DataKeys[index].Value.ToString()); try { if (e.CommandName == "del") { OracleConnection conn = new OracleConnection(ConnectionString); string str = "delete from message where id = " + id + ""; OracleCommand com = new OracleCommand(str, conn); conn.Open(); com.ExecuteNonQuery(); conn.Close(); } } catch { } }
<asp:TemplateField ShowHeader="False" HeaderText="删除"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="del" CommandArgument='"<%Eval("ID")%>"' OnClientClick="javascript:return confirm('确定删除吗?')" Text="删除"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>