本文介绍了如何获取listview中复选框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想知道如何在listview中获取checkbox的值并插入数据库。我收到错误对象引用没有设置为对象的实例。



这是我的代码



hi guys,

i want to know how to get the value of checkbox in listview and inserting to database. i got error " Object reference not set to an instance of an object."

this is my code

Dim myConnection As SqlConnection = New SqlConnection(connectionString)
        myConnection.Open()
        Dim item As ListViewDataItem
        Dim checkbox1 As CheckBox = DirectCast(ListView2.FindControl("Approve"), CheckBox)
        Dim checkbox2 As CheckBox = DirectCast(ListView2.FindControl("Dissapprove"), CheckBox)

        For Each item In ListView2.Items

            If checkbox1.Checked = True Then

                Dim c As New SqlCommand("update butiran_hantar set status=@status where depoh = ''" + Label4.Text + "''", myConnection)
                c.Parameters.AddWithValue("@status", checkbox1.Text)

                Try
                    c.ExecuteNonQuery()
                    myConnection.Close()
                    BindData()
                    Label1.Text = "success."
                Catch ex As Exception
                    Label1.Text = ex.Message.ToString()
                End Try



            ElseIf checkbox2.Checked = True Then
                Dim c As New SqlCommand("update butiran_hantar set status=@status where depoh = ''" + Label4.Text + "''", myConnection)
                c.Parameters.AddWithValue("@status", checkbox2.Text)

                Try
                    c.ExecuteNonQuery()
                    myConnection.Close()
                    BindData()
                    Label1.Text = "success."
                Catch ex As Exception
                    Label1.Text = ex.Message.ToString()
                End Try
            End If


        Next





真的需要帮助。我不知道哪个部分是错的。错误就行了.check1.checked



问候,

musiw。



really need help.i dont know which part is wrong.the error is at the line checkbox1.checked

regards,
musiw.

推荐答案


这篇关于如何获取listview中复选框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 23:12
查看更多