p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

aspdotnet_website_programming thread: Get values from a DataGrid

Message #1 by "Mathias P" <mathiaspatrikson@y...> on Fri, 28 Feb 2003 09:52:19
I?ve got a datagrid to which I databind a dataset that has two columns, I 
also add a checkbox column to the datagrid. At a given moment I want to 
loop through the datagrid to get the value from the checkbox and the 
value from one of the other columns (column name: IdTour) in the datagrid 
to use those to make an insert in the DB. I?ve got the code to loop 
through the datagrid and to get the values from the checkboxes, but I 
don?t have the code to get the value from the other columns. Can anyone 
help me out with this one?

The .ASP code for the datagrid is as follows: 

<asp:datagrid id="dgPlaysOn" runat="server" Height="103px" 
		<asp:BoundColumn DataField="IdTour" 
		<asp:BoundColumn DataField="name" HeaderText="Plays 
		<ItemStyle HorizontalAlign="Center"></ItemStyle>
				<asp:CheckBox ID="chkPlaysOn" 
OnCheckedChanged="GetIdTour" Runat="server" />

And the code in the code behind section is as follows: 

Dim i As Byte 'Loop index
Dim item As DataGridItem 'used to access the individual grid items
Dim cbPlaysOn As CheckBox 'Used to acces the individual checkbox 
Dim bPlaysOn As Boolean

For i = 0 To dgPlaysOn.Items.Count - 1
	item = dgPlaysOn.Items(i)
      cbPlaysOn = CType(item.FindControl("chkPlaysOn"), CheckBox)
      bPlaysOn = cbPlaysOn.Checked
      'Put code to access a specific cell in the column IdTour

      'Put code to call the insert statement

//Mathias P

  Return to Index