Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: CheckBoxList in a Datagrid


Message #1 by "asp" <aspnet@o...> on Thu, 23 Jan 2003 15:45:38 -0500
Is there a way to retrieve the value of which checkbox was clicked in aCheckboxLIst within a datagrid?

Here is  a portion of the code I have so far:

When the user selects/de-selects a check box, I need to update the corresponding record in the database. 


public sub dg_searchResults_OnItemDataBound(sender as object, e as dataGridItemEventArgs)
 dim chk As CheckBoxList  = ctype(e.item.findControl("checkboxList1"),checkBoxList)
 if NOT chk is nothing then
  chk.Items(0).Selected = true
  chk.databind()
 end if
end sub



sub Check_Clicked(sender as Object, e as EventArgs)
  dim chk as CheckBoxList = ctype(sender,CheckBoxList)
  if chk.SelectedIndex = -1
   
   lblNewTest.text = "0 Items clicked"
  else 
   lblNewTest.text = "Item " & (chk.SelectedIndex + 1) & " clicked"
  end if
end sub

<asp:Datagrid ID="dg_SearchResults" AutoGenerateColumns="False" Runat="Server"
      
       OnItemDataBound="dg_searchResults_OnItemDataBound"
           
       >

       <columns>
        <asp:TemplateColumn>
         <ItemTemplate>
          <asp:CheckBoxList 
            id="checkboxlist1" AutoPostBack="True"  OnSelectedIndexChanged="Check_Clicked"    runat="server">
       
           <asp:ListItem>1</asp:ListItem>
           <asp:ListItem>2</asp:ListItem>
           <asp:ListItem>3</asp:ListItem>

          </asp:CheckBoxList>

         </ItemTemplate>
        </asp:TemplateColumn>
       </Columns>
       
      </asp:DataGrid> 



  Return to Index