gpt4 book ai didi

c# - 保存数据后如何更新gridview?

转载 作者:行者123 更新时间:2023-11-29 08:52:25 25 4
gpt4 key购买 nike

我有一个包含 4 列的 GridView (用户 ID、说明、密码、更改密码[按钮])。

当我单击更改密码时,会出现带有 3 个文本框(用户 ID、新密码、确认密码)和保存按钮的面板。

更改密码后,面板消失,但 GridView 中的密码保持与之前相同。

我想更新密码列。

以下是我的保存按钮点击
代码

protected void BindGridView()
{
try
{
DataTable dt = new DataTable();
dt = (DataTable)Session["userinfo"];

gvPassInfo.DataSource = dt;
gvPassInfo.DataBind();
}
catch (Exception ex)
{
//lblMessage.Text = DataObjects.Error_Message();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
clsUser objuser = new clsUser();
string user = txtUserid.Text;
string NewPassword = txtNewPassword.Text;
string ConfirmPassword = txtConfirmNewPassword.Text;
objuser.UpdateSystemPassword(user, NewPassword);
Response.Write("<script LANGUAGE='JavaScript' >alert('Password Changed Successfully...'); document.location='" +ResolveClientUrl("~\\PasswordInformation_Details.aspx") + "'; </script>");
BindGridView();
panelChangePassword.Visible = false;

}
protected void btnSearch1_Click(object sender, EventArgs e)
{
try
{
using (MySqlConnection conn = new MySqlConnection(clsUser.connStr))
{
conn.Open();
string strQuery = "select DISTINCT user_id,description,sap_system_password from sap_password_info where user_id is not null";
if (txtSid.Text !="")
{
strQuery += " AND sid = '" + txtSid.Text + "'";
}
if (txtClient.Text != "")
{
strQuery += " AND client_no = '" + txtClient.Text + "'";
}
if (txtUser.Text != "")
{
strQuery += " AND user_id = '" + txtUser.Text + "'";
}

MySqlCommand cmd = new MySqlCommand(strQuery, conn);
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection));
Session["userinfo"] = dt;
Response.Redirect("~\\PasswordInformation_Details.aspx");
}
}
catch (Exception ex)
{
//lblMessage.Text = DataObjects.Error_Message();
lblMsg.Text = ex.Message.ToString();
}

}

代码是用C#编写的,后端是MySQL DB服务器..请帮忙..

最佳答案

在button_click事件中,将gridview绑定(bind)到一个新列表。

List<something> k = //your sql stuff
GridView1.DataSource = k;
GridView1.DataBind();

关于c# - 保存数据后如何更新gridview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10831554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com