2个回答
2013-09-19
展开全部
1.选中gridview,然后右击,添加项 添加命令项中的添加,并且把外观中的buttontype设置成button.
2.在前台代码中添加OnRowEditing="GridView1_RowEditing"
<asp:GridView ID="GridView1" runat="server" Height="291px" Width="482px"
OnRowDeleting="GridView1_RowDeleting "
( 如 )OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
3.在后台代码中
添加
//绑定
public void bind()
{
GridView1.DataKeyNames = new string[] { "编号", "说明", "子编号", "子编号说明" };//主键
mysql.ExecAdapyerBing3(GridView1, "hbgbbm3");//绑定gridview
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
//当前编辑行背景色高亮
this.GridView1.EditRowStyle.BackColor = System.Drawing.Color.FromName("#F7CE90");
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//根据自己的程序 需要修改
string txt1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string txt2 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string UpdateStr = "update 后备干部编码 set 说明='" + txt1 + "',子编号说明=' " + txt2 + "' where 编号=" + this.GridView1.DataKeys[e.RowIndex].Value + " and 子编号=" + this.GridView1.DataKeys[e.RowIndex].Values[2].ToString();
try
{
mysql.ExecSqlCon(UpdateStr);//自己写一个方法
Response.Write("<script language='javascript'>alert('修改成功!');</script>");
}
catch (Exception exp)
{
Response.Write("<script language='javascript'>alert('" + exp.Message + "');</script>");
}
finally
{
this.GridView1.EditIndex = -1;
bind(); //自定义绑定
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
2.在前台代码中添加OnRowEditing="GridView1_RowEditing"
<asp:GridView ID="GridView1" runat="server" Height="291px" Width="482px"
OnRowDeleting="GridView1_RowDeleting "
( 如 )OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
3.在后台代码中
添加
//绑定
public void bind()
{
GridView1.DataKeyNames = new string[] { "编号", "说明", "子编号", "子编号说明" };//主键
mysql.ExecAdapyerBing3(GridView1, "hbgbbm3");//绑定gridview
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
//当前编辑行背景色高亮
this.GridView1.EditRowStyle.BackColor = System.Drawing.Color.FromName("#F7CE90");
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//根据自己的程序 需要修改
string txt1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string txt2 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
string UpdateStr = "update 后备干部编码 set 说明='" + txt1 + "',子编号说明=' " + txt2 + "' where 编号=" + this.GridView1.DataKeys[e.RowIndex].Value + " and 子编号=" + this.GridView1.DataKeys[e.RowIndex].Values[2].ToString();
try
{
mysql.ExecSqlCon(UpdateStr);//自己写一个方法
Response.Write("<script language='javascript'>alert('修改成功!');</script>");
}
catch (Exception exp)
{
Response.Write("<script language='javascript'>alert('" + exp.Message + "');</script>");
}
finally
{
this.GridView1.EditIndex = -1;
bind(); //自定义绑定
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
2013-09-19
展开全部
运行2012
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询