Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

Discussion in 'ASP .Net Web Controls' started by asp123 vbnet via .NET 247, Mar 25, 2005.

  1. 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.



    --------------------------------
    From: asp123 vbnet

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>64DgJSj5k0ebIIC73MHgoA==</Id>
    asp123 vbnet via .NET 247, Mar 25, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Francois Verbeeck
    Replies:
    0
    Views:
    1,873
    Francois Verbeeck
    Jun 24, 2003
  2. Empire City
    Replies:
    1
    Views:
    3,026
    =?Utf-8?B?bWFoc2E=?=
    Jun 15, 2004
  3. darkpeace
    Replies:
    1
    Views:
    987
    darkpeace
    Jan 23, 2005
  4. Patrick.O.Ige
    Replies:
    5
    Views:
    19,078
    Patrick.O.Ige
    Jun 19, 2005
  5. Rob Edwards

    Checkbox Lists - Retrieving Selected Entry

    Rob Edwards, Nov 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    115
    Rob Edwards
    Nov 22, 2006
Loading...

Share This Page