如何在asp.net中重定向到具有多个结果的另一个页面
本文关键字:结果 另一个 asp net 重定向 | 更新日期: 2023-09-27 18:13:17
我在asp.net工作。在我的应用程序中,如果管理员想要查看年龄从20岁到30岁的用户列表,他将给出范围并单击搜索按钮。点击后,管理员将被重定向到另一个页面,该页面将根据年龄范围显示用户列表。我想在gridview中显示结果。我遇到的问题是,我不知道如何将多个用户传递到另一个页面上的按钮单击,以便在那里我可以绑定网格与结果。
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(strCon))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Profile_ID, FirstName + ' ' + LastName as Name, Age, Occupation, Education, Number, Email, City from UserProfile where Age BETWEEN " + from.Text + " AND " + to.Text;
cmd.Connection = con;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
// here I have to save the result to pass to the following page
Response.Redirect("Users.aspx");
}
else
{
result.Visible = true;
}
}
}
}
不是在按钮点击函数中获取数据,而是将范围作为参数传递给重定向页面
Response.Redirect("Users.aspx ?低= 20,上层= 30");
并使用Request.QueryString()捕获该页加载时的参数值。现在使用这些捕获参数来获取数据,就像你之前所做的那样,在这里,按钮单击函数并绑定gridview。