【问题标题】:I need to populate my gridview after I select a checkbox from checkboxlist从复选框列表中选择一个复选框后,我需要填充我的网格视图
【发布时间】:2013-02-15 00:42:23
【问题描述】:

从复选框列表中选择一个复选框后,我需要填充我的网格视图。我正在尝试使用循环,如果用户取消选中该复选框,我还需要隐藏网格视图。我使用 sql 语句来提取数据。 sql 应该提取与复选框关联的任何数据 '显示所选类别的书籍 Protected Sub chkbListControl_SelectedIndexChanged(sender As Object, e As System.EventArgs) 处理 chkListControl.SelectedIndexChanged

    Dim sqlChecked As String = "select * " _
                              & "from Books, Categories " _
                              & "where Categories.CategoryCode=Books.CategoryCode " _
                              & "order by Title;"

    Dim sqlUnChecked As String = "select * from Books where Categories.CategoryCode=Books.CategoryCode;"

    Dim selectedIndex As Integer = chkListControl.SelectedIndex
    Dim i As Integer

    If (selectedIndex <> -1) Then

        For i = 0 To chkListControl.Items.Count - 1

            If chkListControl.Items(i).Selected Then

                gvwBookList.DataSource = ReturnTable(sqlChecked)
                gvwBookList.DataBind()

            Else

                gvwBookList.DataSource = ReturnTable(sqlUnChecked)
                gvwBookList.DataBind()
                gvwBookList.Visible = False

            End If
        Next
    End If

End Sub

【问题讨论】:

    标签: asp.net sql vb.net gridview checkboxlist


    【解决方案1】:

    你需要像这样修改你的 sqlchecked

     dim selectedcategories as string=""
      If (selectedIndex <> -1) Then
    
        For i = 0 To chkListControl.Items.Count - 1
    
            If chkListControl.Items(i).Selected Then
    
             if selectedcategories="" then
                selectedcategories=chkListControl.Items(i).value
             else
                selectedcategories &="," & chkListControl.Items(i).value
             end if
    
            End If
        Next
    End If
    
     dim strSQL as string=""
                 if selectedcategories.trim<>"" then
                        strSQL = "select * " _
                              & "from Books, Categories " _
                              & "where Categories.CategoryCode=Books.CategoryCode and                     Categories.CategoryCode in (" & selectedcategories &  ")" _
                              & "order by Title;"
       else
    strSQL="select * from Books where Categories.CategoryCode=Books.CategoryCode;"
    
       end if
    
                gvwBookList.DataSource = ReturnTable(strSQL)
                gvwBookList.DataBind()
    

    您可以根据自己的需要修改以上代码。

    【讨论】:

      猜你喜欢
      • 2014-11-01
      • 1970-01-01
      • 2023-03-04
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多