Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

  • Thread starter asp123 vbnet via .NET 247
  • Start date
A

asp123 vbnet via .NET 247

Hello to the community,

I am hoping someone will correct me and help me with thisunderstanding my problem. I am trying to add a checkboxlist or acheckbox templatecolumn to my data grid, and would also like toretrieve the values selected and add them to the database. Thecheckbox would take on the zip codes selected. The code in thebtnAddSvcArea was obtained from a very good post here itselffrom Jeffrey Tan.
This is what I currently have:
<asp:datagrid id="dgZipCode" runat="server"BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"BackColor="White" CellPadding="4" AutoGenerateColumns="False"Width="300" ItemStyle-Wrap="false" >
<Columns>
<asp:templatecolumn>
<itemtemplate>
<asp:checkbox runat="server" Enabled="true" id="chk1" />
</itemtemplate>
</asp:templatecolumn>
<asp:BoundColumn DataField="ZipCode" />
<asp:BoundColumn DataField="City" />
<asp:BoundColumn DataField="State" />
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099"BackColor="#FFFFCC"></PagerStyle>
</asp:datagrid>


Private Sub btnAddSvcArea_Click(ByVal sender As Object, ByVal eAs System.EventArgs) Handles btnAddSvcArea.Click
Dim dgi As DataGridItem
For Each dgi In dgZipCode.Items
Dim tc As TableCell = dgi.Cells(0)

Dim c As Control
For Each c In tc.Controls
If TypeOf (c) IsSystem.Web.UI.WebControls.CheckBox Then
Dim cb As CheckBox = CType(c, CheckBox)
If cb.Checked = True Then
Me.Response.Write("The " &dgi.ItemIndex.ToString() & "th row is selected<br>")
End If
End If
Next
Next
End Sub


I've tried doing this:
<asp:templatecolumn>
<itemtemplate>
<asp:checkbox runat="server" Enabled="true" id="<%#Container.DataItem("ZipCode") %>"/>
</itemtemplate>
</asp:templatecolumn>

But i get a "server tag is not well formed" ...

Can anyone point me in the right direction for the right way ofbinding the values of zip code to the checkbox ? And alsoretrieve the values selected (which would be getting thezipcodes value since the checkboxes should have the zip codevalues).

thank you so much for your replies/help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top