.net中使用DatagridView的增删改方法
2013-01-29 16:22:55 来源:WEB开发网核心提示://更新记录string sql = string.Format("delete dbo.GroupType_Demo where num={0}", Num);try{int i = SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), Comma
//更新记录
string sql = string.Format("delete dbo.GroupType_Demo where num={0}", Num);
try
{
int i = SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql);
if (i > 0)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script language='javascript'>alert('删除成功!')</script>");
}
else
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script language='javascript'>alert('删除失败!')</script>");
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script language='javascript'>alert('操作无效!')</script>");
}
GridView1.EditIndex = -1;
GridViewBind();
}
/// <summary>
/// 添加按钮
/// </summary>
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default_Add.aspx");
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
//行号
int i = e.NewSelectedIndex;
GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
btnAdd.Text = "你选中了第" + (i+1) + "行。";
}
}
}
执行后的页面效果:
string sql = string.Format("delete dbo.GroupType_Demo where num={0}", Num);
try
{
int i = SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql);
if (i > 0)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script language='javascript'>alert('删除成功!')</script>");
}
else
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script language='javascript'>alert('删除失败!')</script>");
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script language='javascript'>alert('操作无效!')</script>");
}
GridView1.EditIndex = -1;
GridViewBind();
}
/// <summary>
/// 添加按钮
/// </summary>
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default_Add.aspx");
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
//行号
int i = e.NewSelectedIndex;
GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
btnAdd.Text = "你选中了第" + (i+1) + "行。";
}
}
}
执行后的页面效果:
Tags:net 使用 DatagridView
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接