【问题标题】:Filtering GridView using Hyperlinks ASP.Net使用超链接 ASP.Net 过滤 GridView
【发布时间】:2016-10-01 23:11:39
【问题描述】:

我有一个连接到 SQL 数据库的 GridView,第一列中有超链接,标记为 ID。单击此超链接时,它将把用户带到另一个页面,上面有另一个 GridView 项目,连接到同一架构中的不同表。

有没有办法使用超链接文本来过滤这个新的 GridView 表上的结果。

Tnaks

【问题讨论】:

    标签: c# asp.net gridview hyperlink


    【解决方案1】:

    使用查询字符串从第一页传递 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      相关资源
      最近更新 更多