protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
???????
????????
}
用这个控件能够显示连接的数据库里面的信息,但是无法修改和删除,进入后台
GridView 控件是空白的, 请问哪位知道后台的 修改 删除该怎么写??
{
???????
????????
}
用这个控件能够显示连接的数据库里面的信息,但是无法修改和删除,进入后台
GridView 控件是空白的, 请问哪位知道后台的 修改 删除该怎么写??
在修改事件中,大概是这样子
gridview对象id.EditIndex=e.item.index;
重新绑定;这个即可进入编辑页面
更新事件rowUpdate
获取更新内容和关键字id
更新数据库
让editindex为-1
重新绑定
删除事件
关键是获取当前行的关键id就可以了,根据id进行数据库操作之后也得重新绑定下
如果你要的是修改删除,就是在相应的时间中写代码就可以了~
主要改SQL语句
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{ // 这里面的代码为空的, 是不是这里面要写什么代码才能正常操作数据库?该如何填写~····
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
{
gv.EditIndex = e.RowIndex;
int id = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
string str = ((TextBox)gv.Rows[e.RowIndex].FindControl("txt")).Text.Trim();
gv.EditIndex = -1;
BindData();
}
{
if (!IsPostBack)
{
geTBind1();
}
}
private void geTBind1()
{
string str = ConfigurationManager.ConnectionStrings["wish"].ConnectionString;
string sql1 = "select StudentId,StudentCard,StudentName,Gender,Birthday,IdentityCard,Address from Student";
SqlConnection cn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(sql1, cn);
cn.Open();
SqlDataAdapter dat = new SqlDataAdapter(cmd);
DataSet dst = new DataSet();
dat.Fill(dst);
GridView1.DataSource = dst;
GridView1.DataBind();
cn.Close();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "d")
{
int id = Convert.ToInt32(e.CommandArgument);
string st = ConfigurationManager.ConnectionStrings["wish"].ConnectionString;
string sql = "delete from Student where StudentId=@id";
SqlConnection con = new SqlConnection(st);
SqlCommand cm = new SqlCommand(sql, con);
cm.Parameters.AddWithValue("@id", id);
con.Open();
cm.ExecuteNonQuery();
con.Close();
geTBind1(); }
}