gpt4 book ai didi

.net - 启用分页时,在单击按钮时循环所有 gridview 行

转载 作者:行者123 更新时间:2023-12-04 07:01:52 24 4
gpt4 key购买 nike

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

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

  • gridview 总行数
  • 循环遍历 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++;
    }
    }
    }

    最佳答案

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

           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();

    关于.net - 启用分页时,在单击按钮时循环所有 gridview 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1706466/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com