CheckBoxes in DataGrid

ssoft

New Member
Hi Guys,<BR><BR>I have a datagrid and using the item template property of the datagrid I have put a checkbox in each row of the data grid. The whole point of putting the check box on each row is so that the users can select the record(s) and press the delete command button at the bottom of the datagrid. This would allow users to delete multiple records at a time.<BR><BR>However, I have a stupd question. How the hell do I access the checkboxes on the datagrid? How do I determine which check boxes are selected? Does it create an array of checkboxes?<BR><BR>I was wondering if someone could help.<BR><BR>Here is the piece of code<BR><BR><Columns><BR><asp:BoundColumn DataField="FullName" HeaderText="Name"><BR><ItemStyle Width="200px"></ItemStyle><BR></asp:BoundColumn><BR><asp:BoundColumn DataField="UserName" HeaderText="User Name"><BR><ItemStyle Width="200px"><BR></ItemStyle><BR></asp:BoundColumn><BR><asp:TemplateColumn HeaderText="Delete"><BR><ItemStyle Height="25px" width="125px"></ItemStyle><BR> <ItemTemplate><BR> <asp:CheckBox ID="chkDelete"Runat="server"><BR> </asp:CheckBox><BR> </ItemTemplate><BR></asp:TemplateColumn><BR> <BR> </Columns><BR><BR>Ran into the same problem, here is the code to check which boxes have been "checked". You'll need to put an ID attribute in the checkbox template, so you can use FindControl(IDHere)<BR><BR>Just build your SQL and execute it now :-)<BR><BR>Cheers<BR><BR><BR>Sub btnDelete_OnClick(ByVal sender As Object, ByVal e As EventArgs)<BR> Dim myDataGridItem As DataGridItem<BR> Dim chkSelected As CheckBox<BR> Dim strReferralID As String<BR><BR> lblStatus.Text = "You selected the Following items:"<BR><BR> For Each myDataGridItem In dgYourDatagrid.Items<BR> chkSelected = myDataGridItem.FindControl("chkSelection")<BR> If chkSelected.Checked Then<BR> strReferralID = CType(myDataGridItem.FindControl("ReferralID"), Label).Text<BR> lblStatus.Text += " The ReferralID is <b>" & strReferralID & "</b>"<BR> End If<BR> Next<BR>End Sub<BR>
 
Back
Top