我有一个连接到 SQL 数据库的 GridView,第一列中有超链接,标记为 ID。单击此超链接时,它将用户带到另一个页面上有另一个 GridView 项的页面,该页面连接到同一架构中的其他表。
有没有办法使用超链接文本来筛选这个新的 GridView 表上的结果。
啪��
使用查询字符串从第一个页面传递 id
对于在 where 子句中使用此查询字符串的网格
例如:
protected void Page_Load(object sender, EventArgs e)
{
int id=0;
if(Request.QueryString["id"] !=null)
{
id=int.parse(Request.QueryString["id"].toSting());
}
if (!IsPostBack)
{
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlDataSource1.SelectCommand = "SELECT * from table where id="+id;
GridView1.DataSource = SqlDataSource1;
GridView1.DataBind();
}
}
您的页面网址将如下所示
www.Something.com/yourPage.aspx?id=77