[英]How to redirect to another page with muiltple results in asp.net
我在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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.