protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
        {
            
             foreach (GridViewRow row in this.GridView1.Rows)
            {
                HyperLink link = (HyperLink)e.Row.Cells[4].Controls[0];
                string Member_order_ID = link.Text.Trim();
                if (e.Row.Cells[5].Text == "重复消费")
                {
                    HyperLink hyl = (HyperLink)row.FindControl("EditID");
                    hyl.NavigateUrl = "OrderAgain.aspx?Member_Order_ID=" + Member_order_ID;
                }
            }
        } 
    }
----------------------------------
 为什么hyl.NavigateUrl得值是一样的,都是最后一个

解决方案 »

  1.   

    好像在 RowDataBound不用在循环了,你把foreach去掉
     HyperLink link = (HyperLink)e.Row.Cells[4].Controls[0];
                    string Member_order_ID = link.Text.Trim();
                    if (e.Row.Cells[5].Text == "重复消费")
                    {
                        HyperLink hyl = (HyperLink)e.Row.FindControl("EditID");
                        hyl.NavigateUrl = "OrderAgain.aspx?Member_Order_ID=" + Member_order_ID;
    }
    如果不行就在绑定后的代码中用下面的
    foreach (GridViewRow row in this.GridView1.Rows)
                {
                   //把e.Row改为row
                    HyperLink link = (HyperLink)row.Cells[4].Controls[0];
                    string Member_order_ID = link.Text.Trim();
                    if (row .Cells[5].Text == "重复消费")
                    {
                        HyperLink hyl = (HyperLink)row.FindControl("EditID");
                        hyl.NavigateUrl = "OrderAgain.aspx?Member_Order_ID=" + Member_order_ID;
                    }