62,074
社区成员
发帖
与我相关
我的任务
分享
SqlConnection strConl;
SqlCommand strCom;
string strCon = "Data Source=.;Database=master;Uid=sa;Pwd=yu";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strSql = "delete from ygInfo where id = '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
strConl = new SqlConnection(strCon);
strCom = new SqlCommand(strSql, strConl);
strConl.Open();
strCom.ExecuteNonQuery();
strConl.Close();
bind();
}
public void bind()
{
string strSql = "select * from ygInfo";
strConl = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter(strSql, strCon);
DataSet ds = new DataSet();
strConl.Open();
da.Fill(ds, "ygInfo");
GridView1.DataSource = ds;
GridView1.DataKeyNames = new string[] { "id" };
GridView1.DataBind();
}