这是aspx文件里gridview的帮定删除列. 已经设置好了datakeyname 为 id
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:ImageButton CommandName="delete" ID="imgdel" Runat="server"ImageUrl="../images/delete.gif" CssClass="input_hand" AlternateText="删除">
</asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>这是删除事件代码.但是这是有问题的事件代码,大家帮我看看.
protected void Fw_delete(object sender, GridViewDeletedEventArgs e)
{
string autoid = this.GridView1.DataKeys[e.Item.ItemIndex]; string Strcon = System.Configuration.ConfigurationSettings.AppSettings["connection"];
SqlConnection sqlconn = new SqlConnection(Strcon);
sqlconn.Open();
SqlCommand mySqlCommand = sqlconn.CreateCommand();
mySqlCommand.CommandText = "execute usp_com_ygtfmng_delete @autoid";
mySqlCommand.Parameters.Add("@autoid", SqlDbType.NVarChar, 50).Value = autoid;
mySqlCommand.ExecuteNonQuery();
Common.Message(this, "数据删除成功");
}
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:ImageButton CommandName="delete" ID="imgdel" Runat="server"ImageUrl="../images/delete.gif" CssClass="input_hand" AlternateText="删除">
</asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>这是删除事件代码.但是这是有问题的事件代码,大家帮我看看.
protected void Fw_delete(object sender, GridViewDeletedEventArgs e)
{
string autoid = this.GridView1.DataKeys[e.Item.ItemIndex]; string Strcon = System.Configuration.ConfigurationSettings.AppSettings["connection"];
SqlConnection sqlconn = new SqlConnection(Strcon);
sqlconn.Open();
SqlCommand mySqlCommand = sqlconn.CreateCommand();
mySqlCommand.CommandText = "execute usp_com_ygtfmng_delete @autoid";
mySqlCommand.Parameters.Add("@autoid", SqlDbType.NVarChar, 50).Value = autoid;
mySqlCommand.ExecuteNonQuery();
Common.Message(this, "数据删除成功");
}
解决方案 »
- 分享 C#不用treeview控件生成漂亮的树型结构
- 多个select如何获取最后一个,在线等
- asp.net中分页的gridview导出数据
- 问题的关键是,我不是J2EE专家!!!
- 如何判断用户是从地址栏输入地址访问页面的
- 高分.net版本的许愿墙源码
- 关于ASP:TEXTBOX的控件出现的问题
- 如何从数据库中把IMAGE类型的图片显示在页面上??在线等待。。。
- 如何将一个Session变量由一个web站点传递到另一个web站点。
- 如何控制DropDownList中每一项的颜色?
- ComponentOne控件生成折線圖,怎麼樣才能在折線的端點顯示出它的數字呢。!!!!
- 请问使用JS如何给RadioButtonList添加选项
string autoid = this.GridView1.DataKeys[e.Item.ItemIndex];
gridview不是这样写吧?GridView1.DataKeys[e.Row.RowIndex].Value吧