【问题标题】:loop all gridview rows on button click when paging enabled启用分页时,在单击按钮时循环所有 gridview 行
【发布时间】:2009-11-10 08:48:53
【问题描述】:

我在我的 gridview 中启用了分页...

我在按钮点击事件中需要这个

  1. gridview 总行数
  2. 循环遍历 foreach 中的所有行

但它只适用于当前的 gridview 页面...帮助

protected void Button5_Click(object sender, EventArgs e)
{
    int[] no = new int[GridView2.Rows.Count];
    int i = 0;

    foreach (GridViewRow row in GridView2.Rows)
    {            
        Label l = (Label)row.FindControl("Label2");
        if (l.Text == "Unpaid")
        {
            int productID = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);
            no[i] = productID;
            i++;
         }
     }
}

【问题讨论】:

    标签: .net gridview


    【解决方案1】:

    要实现你必须在循环之前禁用分页。重新绑定网格并执行循环。 然后启用分页并再次绑定网格。

           protected void Button5_Click(object sender, EventArgs e)       
     { 
    GridView2.AllowPaging = false;
     // do your databind here 
    GridView2.databind(); 
    int[] no = new int[GridView2.Rows.Count];      
              int i = 0;        
        foreach (GridViewRow row in GridView2.Rows)      
          {                             
       Label l = (Label)row.FindControl("Label2");
                        if (l.Text == "Unpaid")        
                {                    
        int productID = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);                        no[i] = productID;                        i++;                    }                }  
    
    
                  )
    
    
    
    GridView2.AllowPaging = true;
            // do your databind here again
            GridView2.databind();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多