protected void GV_yaoqiu_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GV_yaoqiu.EditIndex = -1;
yaoqiu_databind();
}
protected void GV_yaoqiu_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GV_yaoqiu.DataKeys[e.RowIndex].Values[0].ToString();
string sql = "delete from T_Require where PK_Require=" + id;
try
{
int i = DbHelperSQL.ExecuteSql(sql);
GV_yaoqiu.EditIndex = -1;
yaoqiu_databind();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message.ToString() + "');</script>");
}
}
protected void GV_yaoqiu_RowEditing(object sender, GridViewEditEventArgs e)
{
GV_yaoqiu.EditIndex = e.NewEditIndex;
yaoqiu_databind();
}
protected void GV_yaoqiu_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GV_yaoqiu.DataKeys[e.RowIndex].Values[0].ToString();
string require_name = ((TextBox)GV_yaoqiu.Rows[e.RowIndex].FindControl("tb_yaoqiu")).Text.Trim();
string sqltext = "update T_Require set require_name='" + require_name + "' where PK_Require=" + id;
try
{
int i = DbHelperSQL.ExecuteSql(sqltext);
GV_yaoqiu.EditIndex = -1;
yaoqiu_databind();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message.ToString() + "');</script>");
}
}
protected void GV_yaoqiu_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) //添加删除询问
{
e.Row.Cells[3].Attributes.Add("onclick", "javascript:return confirm('你确认要删除该记录吗?')");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
try
{
string newrequire = ((TextBox)this.FindControl("new_yaoqiu")).Text.Trim();
string sql = "insert into T_Require(require_name) values('" + newrequire + "') ";
DbHelperSQL.ExecuteSql(sql);
yaoqiu_databind();
((TextBox)this.FindControl("new_yaoqiu")).Text = string.Empty;
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message.ToString() + "');</script>");
}
}
}
private void yaoqiu_databind() //数据绑定函数
{
string sql = "select PK_Require ,Require_name from T_Require order by PK_Require";
try
{
GV_yaoqiu.DataSource = DbHelperSQL.Query(sql).Tables[0].DefaultView;
GV_yaoqiu.DataBind();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
}
}