0

4 つの列 (ユーザー ID、説明、パスワード、パスワードの変更 [ボタン]) を持つ 1 つのグリッド ビューがあります。

パスワードの変更をクリックすると、3 つのテキストボックス (ユーザー ID、新しいパスワード、パスワードの確認) と保存ボタンを含むパネルが表示されます。

パスワードを変更した後、パネルは消えますが、グリッドビューのパスワードは以前と同じままです。

パスワード列を更新したい。

以下は私の保存ボタンのクリック
コード です

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 サーバーです。助けてください。

4

3 に答える 3

1

このチュートリアルを読んでください。また、インターネット上には、ASP.NET の初心者向けのチュートリアルがたくさんあります。グーグルで..

編集:パスワードを保存した後、datatableデータベースから(セッションからではなく)ロードし、グリッドビューに再度バインドします。

そのように

DataTable dt = new DataTable();
dt = //LoadFromDB();    // load data from database not session

gvPassInfo.DataSource = dt;
gvPassInfo.DataBind(); 
于 2012-05-31T10:29:12.910 に答える
1

button_click イベントで、グリッドビューを新しいリストにバインドします。

List<something> k = //your sql stuff
GridView1.DataSource = k;
GridView1.DataBind();
于 2012-05-31T10:14:02.570 に答える
0

更新イベント/保存ボタンクリックイベントGridViewの最後に更新します

編集

データベースのレコードを更新していますが、新しいデータを取得していないため、古い情報を取得しています

したがって、次のステートメントがデータベースからデータを取得し、セッションデータセットを新しいデータで更新すると、問題は解決します...

 objuser.UpdateSystemPassword(user, NewPassword);
 //get the updated data from the database after this statement
 //don't forget to update the session with new data

古いページにこのコードを書きます

Dictionary<string,string> infor = new Dictionary<string,string>();
infor["sid"] = txtSid.Text;
infor["client_no"] = txtClient.Text;
..
...
Session["queryInfo"] = infor;

新しいファイルで

GetDataFromDB()
{
Dictionary<string,string> infor = (Dictionary<string,string>)Session["queryInfo"];

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 (infor["sid"] !="")
        {
            strQuery += " AND sid = '" + infor["sid"] + "'";
        }
        //... do like above for remaining if conditions

        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)
{
     throw;
}
}
于 2012-05-31T10:16:24.457 に答える