|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding Checkboxlist/checkbox to dataGrid and retrieving selected valueI am hoping someone will correct me and help me with this understanding my problem. I am trying to add a checkboxlist or a checkbox templatecolumn to my data grid, and would also like to retrieve the values selected and add them to the database. The checkbox would take on the zip codes selected. The code in the btnAddSvcArea was obtained from a very good post here itself from 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 e As 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) Is System.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 of binding the values of zip code to the checkbox ? And also retrieve the values selected (which would be getting the zipcodes value since the checkboxes should have the zip code values). thank you so much for your replies/help. -------------------------------- From: asp123 vbnet ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>64DgJSj5k0ebIIC73MHgoA==</Id>
Other interesting topics
|
|||||||||||||||||||||||