for ( t = 0; t < dt.Rows.Count;t++ )
        {
           
            LinkButton lbn = new LinkButton();
            lbn.ID = "lbn"+t;
            lbn.Text = dt.Rows[t]["Keyword"].ToString()+"&nbsp";
            product = dt.Rows[t]["Keyword"].ToString() + "&nbsp";
           
            lbn.Click += new EventHandler(lbn_Click);
            this.Panel1.Controls.Add(lbn);
        }public void lbn_Click(object sender, EventArgs e)
    {        Response.Redirect("~/info/BizDetail.aspx?pro=" + Server.HtmlEncode(product));
    }
从数据库读到几条记录,然后把他们动态的在页面上显示,现在通过单击事件要把读到的product 作为参数传到另页面,可是 product因为在循环中,所以会被覆该,传过去的是最后读到的那个记录,请问怎么做才能穿过去的是点击按钮对应的记录

解决方案 »

  1.   

    把product定义在循环外面不行吗
      

  2.   

    product 声明为List吧,然后村在ViewState中
      

  3.   

    你这个有什么用啊?你这样做,lbn和product的值都是最后读的那个.你可以写成这样:
    Response.Redirect("~/info/BizDetail.aspx?pro=" + Server.HtmlEncode(sender.ToString()));
      

  4.   

    按钮ID作为 键     product  作为值     加入 Hashtable
      

  5.   

    product对象通过session等传递
    或属性 server.transfer
    数值等类型post传递
      

  6.   

    这结贴率!---------楼主资料---------
    登录名:willjacky33
    总技术分:0
    总技术排名:424472
    ---------结贴情况---------
    截至:2010-08-26 11:17:33
    总发帖:9个
    正常结贴:4个
    未结贴:5
    结贴率:44.44%评语:楼主,说真的你的结贴率非常不高哇!
    --------------------------
      

  7.   

    lbn.Click += new EventHandler(lbn_Click);把你的这句代码方在你的循环外面不就OK了吧
      你这样写的话 肯定 获取的是最后一个product  的呀·
      

  8.   

    Response.Redirect("~/info/BizDetail.aspx?pro=你读取的记录);
    然后在 新的页面用request.querystring("pro")获取这条记录,最后显示出来就好了
      

  9.   

    扯淡for (t = 0; t < dt.Rows.Count; t++)
    {    LinkButton lbn = new LinkButton();
        lbn.ID = "lbn" + t;
        lbn.Text = dt.Rows[t]["Keyword"].ToString() + "&nbsp";
        product = dt.Rows[t]["Keyword"].ToString() + "&nbsp";
        lbn.PostBackUrl = "~/info/BizDetail.aspx?pro=" + Server.HtmlEncode(product);    //lbn.Click += new EventHandler(lbn_Click);    this.Panel1.Controls.Add(lbn);
    }