hi all,
i want to know how to add checkboxes in listview (e.g: Approve / Dissapprove) and save it to database.please help me.i need to submit today
here is my code:
For Each item In ListView2.Items
Dim chk1 As CheckBox = item.FindControl("CheckBox1")
Dim chk2 As CheckBox = item.FindControl("CheckBox2")
If chk1.Checked Then
Dim c As New SqlCommand("update butiran_hantar set status=@status where depoh = '" + Label4.Text + "'", myConnection)
c.Parameters.AddWithValue("@status",chk1.Text)
Try
c.ExecuteNonQuery()
BindData()
'Label1.Text = "success."
Catch ex As Exception
Label1.Text = ex.Message.ToString()
End Try
ElseIf chk1.Checked Then
Dim c As New SqlCommand("update butiran_hantar set status=@status where depoh = '" + Label4.Text + "'", myConnection)
c.Parameters.AddWithValue("@status", chk2.Text)
Try
c.ExecuteNonQuery()
BindData()
Label1.Text = "success."
Catch ex As Exception
Label1.Text = ex.Message.ToString()
End Try
End If
Next
<asp:ListView ID="ListView2" runat="server" >
<LayoutTemplate>
<table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all" width="100%">
<tr style="background-color: #336699; color: White;">
<th align="center">Bil</th>
<th align="center">Depoh</th>
<th align="center">Stokereta</th>
<th align="center">Jenis Roda</th>
<th align="center">Saiz Roda</th>
<th align="center">Flange</th>
<th align="center">Hollow</th>
<th align="center">Tindakan</th>
<th align="center">Skidded</th>
<th align="center">Catatan</th>
<th align="center">Approve</th>
<th align="center">Dissapprove</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:Label ID="bil" runat="server" Text=<%# Container.DataItemIndex+1 %>></asp:Label></td>
<td align="center">
<asp:Label ID="lbldepoh" runat="server" Text='<%# Eval("depoh")%>' > </asp:Label></td>
<td align="center">
<asp:Label ID="lblstokereta" runat="server" Text='<%# Eval("stokereta")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lbljenisroda" runat="server" Text='<%# Eval("jenisroda")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lblsaizroda" runat="server" Text='<%# Eval("saizroda")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lblflange" runat="server" Text='<%# Eval("flange")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lblhollow" runat="server" Text='<%# Eval("hollow")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lbltindakan" runat="server" Text='<%# Eval("tindakan")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lblskid" runat="server" Text='<%# Eval("skid")%>'></asp:Label></td>
<td align="center">
<asp:Label ID="lblcatatan" runat="server" Text='<%# Eval("catatan")%>'></asp:Label></td>
<td align="center">
<asp:CheckBox ID="CheckBox1" runat="server" Width="50px" Text="Approve" /></td>
<td align="center">
<asp:CheckBox ID="CheckBox2" runat="server" Width="50px" Text=" Dissapprove" /></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
No records found
</EmptyDataTemplate>
</asp:ListView>