I'm updating the database in the ItemCommand, because the updating should happen when the LinkButtons are clicked.
Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand
If e.CommandName = "Agree" Then
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Using comm As New SqlCommand("UPDATE Table1 SET Agrees=Agrees+1 WHERE ID=@ID", conn)
comm.Parameters.AddWithValue("@ID", e.CommandArgument)
conn.Open()
comm.ExecuteNonQuery()
End Using
End Using
End If
If e.CommandName = "Disagree" Then
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Using comm As New SqlCommand("UPDATE Table1 SET Disagrees=Disagrees+1 WHERE ID=@ID", conn)
comm.Parameters.AddWithValue("@ID", e.CommandArgument)
conn.Open()
comm.ExecuteNonQuery()
End Using
End Using
End If
End Sub
The LinkButtons are disabled in their OnClick events.
Protected Sub LinkButton_Click(sender As Object, e As EventArgs)
Dim lb As LinkButton = DirectCast(sender, LinkButton)
If lb.ID = "Agree" Then
Dim lb2 As LinkButton = DirectCast(DirectCast(lb.NamingContainer, ListViewItem).FindControl("Disagree"), LinkButton)
lb.Enabled = False
lb2.Enabled = False
Else
Dim lb2 As LinkButton = DirectCast(DirectCast(lb.NamingContainer, ListViewItem).FindControl("Agree"), LinkButton)
lb.Enabled = False
lb2.Enabled = False
End If
End Sub
frmeyer
Member
19 Points
67 Posts
Re: How to Databind ListView without enabling LinkButtons
Apr 13, 2012 05:25 PM|LINK
I'm updating the database in the ItemCommand, because the updating should happen when the LinkButtons are clicked.
Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand If e.CommandName = "Agree" Then Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) Using comm As New SqlCommand("UPDATE Table1 SET Agrees=Agrees+1 WHERE ID=@ID", conn) comm.Parameters.AddWithValue("@ID", e.CommandArgument) conn.Open() comm.ExecuteNonQuery() End Using End Using End If If e.CommandName = "Disagree" Then Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) Using comm As New SqlCommand("UPDATE Table1 SET Disagrees=Disagrees+1 WHERE ID=@ID", conn) comm.Parameters.AddWithValue("@ID", e.CommandArgument) conn.Open() comm.ExecuteNonQuery() End Using End Using End If End SubThe LinkButtons are disabled in their OnClick events.
Protected Sub LinkButton_Click(sender As Object, e As EventArgs) Dim lb As LinkButton = DirectCast(sender, LinkButton) If lb.ID = "Agree" Then Dim lb2 As LinkButton = DirectCast(DirectCast(lb.NamingContainer, ListViewItem).FindControl("Disagree"), LinkButton) lb.Enabled = False lb2.Enabled = False Else Dim lb2 As LinkButton = DirectCast(DirectCast(lb.NamingContainer, ListViewItem).FindControl("Agree"), LinkButton) lb.Enabled = False lb2.Enabled = False End If End Subdatabind listview LinkButton