【问题标题】:getting gridview columns values in array list获取数组列表中的gridview列值
【发布时间】:2013-04-27 23:36:52
【问题描述】:

我有 gridview,其中有复选框控件,就像这张图片。

问题是我想使用检查状态的值。意思是如果检查状态然后我想将值分配给这样的字符串867,864。我在这里尝试了一些代码,但它不能正常工作

For Each gvrow As GridViewRow In GridView5.Rows
            Dim chkbox As CheckBox = CType(gvrow.FindControl("chkStatusGM"), CheckBox)
            If chkbox.Checked Then
                Dim bpv As String = GridView5.Rows(0).Cells(3).Text
                Response.Write(bpv)
End If
        Next

但输出是867867 而不是我想要的867,864。请任何人帮助获得所需的输出

【问题讨论】:

    标签: asp.net vb.net gridview checkbox


    【解决方案1】:
    Dim bpv As String = ""
    
    For Each gvrow As GridViewRow In GridView5.Rows
        Dim chkbox As CheckBox = (CheckBox)gvrow.FindControl("chkStatusGM"); 
        If chkbox!= null && chkbox.Checked Then
            If bpv <> "" Then
                bpv += ","
            End If
            bpv += gvrow.Cells(3).Text
        End If
     Next
     Response.Write(bpv)
    

    【讨论】:

    • 先生现在输出是867,867,但根据复选框选择我想要867,864
    • 先生,我认为您没有根据复选框选择动态修复 cell3 的第一行的值,因为我选择了BPV 863,但它再次返回了868,868
    • 现在我从“bpv += GridView5(0).Cells(3).Text”更改为“bpv += gvrow.Cells(3).Text”.. 现在我运行良好跨度>
    • 因为,首先我在代码中查找修复行(0)....现在我修复它并解决了
    【解决方案2】:

    很抱歉用C#给你答案,因为我对VB不熟悉,你可以使用在线转换器将代码转换为VB

    我发现的错误是您应该采用索引和增量,以便检测下一个选中的复选框,如下所示:

    int j = 0;
    foreach (GridViewRow gvRow in GridView1.Rows)
    {
        CheckBox chkSel = (CheckBox)gvRow.FindControl("SelectCheck");
        if (chkSel.Checked)
        {
            string Delete = Convert.ToString(GridView1.Rows[j].Cells[3].Text);
            //Cells[3] is the column to get one by one rows ceslls[3] columns
            Bal_add.Delete(Delete);
        }
        j++;
    }
    

    例如在这种情况下j 是索引并递增它。

    希望这会有所帮助:D

    【讨论】:

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