0

1ページに2つのパネルがあります(SAPInfo、OSInfo)。SAPInfoパネルには、3つのテキストボックス(SID、Client、User_id)と1つの検索ボタンがあります。[検索]ボタンをクリックした後、次のページのグリッドビューにSAPテーブル(user_id、Descriptio、sap_system_password)のデータを表示したいと思います。同様に、OSInfoパネルには、2つのテキストボックス(IP / HostName、User_id)と1つの検索ボタンがあります。[検索]ボタンをクリックした後、同じグリッドビューにOSテーブル(user_id、Descriptio、os_system_password)のデータを表示したいと思います。Gridviewには4つの列(UserID、Description、Password、Change Password)がありますSAPテーブルにはフィールドが含まれていますas(sid、client_no、user_id、sap_system_password、description)OSテーブルにはフィールドが含まれていますas(user_id、ip、host_name、os_system_password、description)これ?助けてください..これは私の検索ボタン(SAP)コードです

protected void btnSAPSearch_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();
    }

}
4

1 に答える 1

0

解決策は非常に簡単です。検索条件をクエリ文字列として他のページに渡します。検索ボタン (SAP パネル) をクリックすると、次のようなクエリ文字列が作成されます。

 //if sap
    string url = "Result.aspx?Mode=SAP&sid=some_sid&client=some_client&user_id=some_user_id;
    Response.Redirect(url, false);

検索ボタンをクリックすると(OSパネル)

//if OS
string url = "Result.aspx?Mode=OS&ip=some_ip&user_id=some_userId;
Response.Redirect(url, false);

ON 結果ページ page_load

if(Request.QueryString["Mode"] =="SAP")
{
    //bring sap result dataset
}
else
{
    // bring os result dataset
}

//bind it to gridView
resultGridView.DataSource = dsResult
resultGridView.DataBind();

覚えておいてください。グリッド ビューで autogeneratedcolumn = true にします。これで、グリッド ビューに結果が表示されます (3 列、4 列)。列は動的に生成されます。

編集1

検索後、結果を含むデータセットが得られます。グリッド ヘッダーを変更するには、dataTable の列名を変更するだけです。あなたが与えるどんな列でも、グリッドによって表示されます

datatable.Columns["original_column_name"].ColumnName = "new column name";

//For adding a new column, just simply do this to your result set
datatable.Columns.Add("Change Password");

編集2

string strQuery = "select DISTINCT user_id as User Id,description as Description,sap_system_password as Sap System Password from sap_password_info where user_id is not null";

これも参照してください:列エイリアス

于 2012-06-04T08:05:29.707 に答える