ASP.NET中gridview在搜索到某条数据时编辑出问题,页面自动加载所有数据,第一行显示编辑状态。 10
如图。我的protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){jiazai();}}publi...
如图。我的
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {
jiazai(); } }
public void jiazai() { GridView1.DataSource= StudentBLL.GetAll(); GridView1.DataBind(); }
查询按钮的代码如下
if (DropDownList1.SelectedValue.ToString() == "学号") { GridView1.DataSource = StudentBLL.selectById(id); GridView1.DataBind(); }
编辑按钮的代码
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { StudentInfor stu = new StudentInfor(); stu.Stuid= int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); stu.Name= (GridView1.Rows[e.RowIndex].FindControl("txtname") as TextBox).Text; stu.Shenfenzheng = (GridView1.Rows[e.RowIndex].FindControl("txtshenfenzheng") as TextBox).Text; stu.Tel = (GridView1.Rows[e.RowIndex].FindControl("txttel") as TextBox).Text; stu.Banji = (GridView1.Rows[e.RowIndex].FindControl("ddlbanji") as DropDownList).SelectedValue.ToString(); if (StudentBLL.updateStudent(stu)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "alert('更新成功!');", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "alert('更新失败!');", true); } GridView1.EditIndex = -1; jiazai(); } catch { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "alert('数据库语句有误!');", true); } }
我要怎么处理这个问题啊?在此先谢过大家了,就这么多分了希望会的可以给说说 展开
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {
jiazai(); } }
public void jiazai() { GridView1.DataSource= StudentBLL.GetAll(); GridView1.DataBind(); }
查询按钮的代码如下
if (DropDownList1.SelectedValue.ToString() == "学号") { GridView1.DataSource = StudentBLL.selectById(id); GridView1.DataBind(); }
编辑按钮的代码
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { StudentInfor stu = new StudentInfor(); stu.Stuid= int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); stu.Name= (GridView1.Rows[e.RowIndex].FindControl("txtname") as TextBox).Text; stu.Shenfenzheng = (GridView1.Rows[e.RowIndex].FindControl("txtshenfenzheng") as TextBox).Text; stu.Tel = (GridView1.Rows[e.RowIndex].FindControl("txttel") as TextBox).Text; stu.Banji = (GridView1.Rows[e.RowIndex].FindControl("ddlbanji") as DropDownList).SelectedValue.ToString(); if (StudentBLL.updateStudent(stu)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "alert('更新成功!');", true); } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "alert('更新失败!');", true); } GridView1.EditIndex = -1; jiazai(); } catch { ScriptManager.RegisterStartupScript(this, this.GetType(), "js", "alert('数据库语句有误!');", true); } }
我要怎么处理这个问题啊?在此先谢过大家了,就这么多分了希望会的可以给说说 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询