C# 循环检查复选框并将复选框值插入数据库

C# 循环检查复选框并将复选框值插入数据库,c#,asp.net,vb.net,C#,Asp.net,Vb.net,ASPX页面: 我哪里出错了?我没有收到任何错误…但这段代码对我不起作用。您只在页面控件中搜索,而您的复选框在页面控件层次结构的更深处 foreach (ListViewItem row in listView.Rows) { if (row.ItemType == ListViewItemType.DataItem) { CheckBox chk = row.FindControl("Checkboxid"); if (chk.Checked) {

ASPX页面:


我哪里出错了?我没有收到任何错误…但这段代码对我不起作用。

您只在页面控件中搜索,而您的复选框在页面控件层次结构的更深处

foreach (ListViewItem row in listView.Rows)
{
  if (row.ItemType == ListViewItemType.DataItem)
  {
    CheckBox chk = row.FindControl("Checkboxid");
    if  (chk.Checked)
    {
     //Write code to store this checkbox value to database here
    }
   }
  }

请使用适当的控件名更改VB中的代码

列表视图位于面板内,复选框位于列表视图内…我想在单击按钮时执行代码…如何执行?我还使用母版页。我获取的ItemRow未定义。Row不是System.Web.UI.WebControl.listview的成员
For i As Integer = 0 To lvSubjects.Items.Count - 1
            Dim coll As ControlCollection = lvSubjects.Items(i).Controls
            For Each c As Control In coll
                If TypeOf c Is CheckBox Then
                    Dim box As CheckBox = CType(c, CheckBox)
                    If box.Checked Then
                        MsgBox(box.Text)
                    End If
                End If
            Next c
        Next i
foreach (ListViewItem row in listView.Rows)
{
  if (row.ItemType == ListViewItemType.DataItem)
  {
    CheckBox chk = row.FindControl("Checkboxid");
    if  (chk.Checked)
    {
     //Write code to store this checkbox value to database here
    }
   }
  }
For i As Integer = 0 To lvSubjects.Items.Count - 1
            Dim coll As ControlCollection = lvSubjects.Items(i).Controls
            For Each c As Control In coll
                If TypeOf c Is CheckBox Then
                    Dim box As CheckBox = CType(c, CheckBox)
                    If box.Checked Then
                        MsgBox(box.Text)
                    End If
                End If
            Next c
        Next i