我在一个页面上有2个面板(SAPInfo,OSInfo)。在SAPInfo面板中,有3个文本框(SID,Client,User_id)和1个SEARCH按钮。单击SEARCH按钮后,我想在下一页的Gridview中显示SAP表的数据(user_id,Descriptio,sap_system_password)。类似地在OSInfo面板中有2个文本框(IP / HostName,User_id)和1个SEARCH按钮。单击SEARCH按钮后,我想在同一Gridview中显示OS表(user_id,Descriptio,os_system_password)的数据。 Gridview有4列(UserID,Description,Password,Change Password)SAP表包含的字段为(sid,client_no,user_id,sap_system_password,description)OS表包含的字段为(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();
}
}
答案 0 :(得分:0)
解决方案非常简单。将搜索条件作为查询字符串传递给您的其他页面。 因此,单击搜索按钮(SAP Panel),构建一个查询字符串,如下所示
//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列)。这些列现在将动态生成。
搜索后,您会得到一些带有结果的数据集。要更改网格标题,只需更改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";
另见:Column Alias