=====ASP.NET的datagrid控件怎么删不掉数据?高手帮忙====
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack);
binddata();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void shanchu(object sender,DataGridCommandEventArgs e)
{
SqlConnection dbcon=new SqlConnection("server=localhost;uid=sa;password=;database=mydatabase;");
SqlCommand cmdel=new SqlCommand();
cmdel.Connection=dbcon;
cmdel.CommandType=CommandType.StoredProcedure;
cmdel.CommandText="shanchugc";
cmdel.Parameters.Add("@id",SqlDbType.Int,5);
cmdel.Parameters["@id"].Value=DataGrid1.DataKeys[(int)e.Item.ItemIndex];
dbcon.Open();
cmdel.ExecuteNonQuery();
SqlCommand cmd=new SqlCommand();
cmd.Connection=dbcon;
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="chucungc";
SqlDataAdapter dapubs=new SqlDataAdapter();
dapubs.SelectCommand=cmd;
DataSet dspubs=new DataSet();
dapubs.Fill(dspubs);
DataGrid1.DataSource=dspubs.Tables[0].DefaultView;
DataGrid1.DataBind();
dbcon.Close();
}
private void binddata()
{
SqlConnection dbcon=new SqlConnection("server=localhost;uid=sa;password=;database=mydatabase;");
SqlCommand cmd=new SqlCommand();
cmd.Connection=dbcon;
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="chucungc";
SqlDataAdapter dapubs=new SqlDataAdapter();
dapubs.SelectCommand=cmd;
DataSet dspubs=new DataSet();
dapubs.Fill(dspubs);
DataGrid1.DataSource=dspubs.Tables[0].DefaultView;
DataGrid1.DataBind();
}
}
}
以上是代码,为什么删不掉数据?刚开始还可以正常删除的,但不知我又动到哪了,点了删除删不掉数据!存储过程没有错误!
问题点数:0、回复次数:2Top
1 楼ofei(nop)回复于 2005-06-04 19:08:20 得分 0
事件丢了~~Top
2 楼hawk5456(雨人)回复于 2005-06-06 09:53:04 得分 0
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.DelGp.Click += new System.EventHandler(this.DelGp_Click);//这个事件丢失!双击你的删除按钮就可以了。
}
Top




