Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

Reply
Thread Tools

Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

 
 
asp123 vbnet via .NET 247
Guest
Posts: n/a
 
      03-25-2005
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving the value of an Selected Item from a Listbox widget doni Perl Misc 1 03-14-2007 06:23 PM
Problem with retrieving the selected value in a dropdown list yasodhai@gmail.com ASP .Net 2 03-09-2007 01:16 PM
Problem with retrieving the selected value in a dropdown list yasodhai@gmail.com ASP .Net Datagrid Control 0 03-09-2007 07:16 AM
reference/retrieving selected value in two radio groups eddie wang Javascript 0 12-15-2003 11:00 PM
--- retrieving text from a selected datagrid cell --- Daniel Bass ASP .Net Datagrid Control 2 07-08-2003 02:18 PM



Advertisments