List Info

Thread: Checkbox Values in a Datagrid




Checkbox Values in a Datagrid
user name
2006-05-23 15:13:27
Are you making sure your not posting back when binding the
grid?  

If Not ispostback then
	Bindgrid()
End if

Thank you
Robert

==============================
Robert Hoenig
x6928


-----Original Message-----
From: Eric Van Buren [mailto:ericvanburenmsn.com]
Sent: Tuesday, May 23, 2006 9:45 AM
To: aspnet-datadisplaycontrolsaspadvice.com
Subject: [aspnet-datadisplaycontrols] Checkbox Values in a
Datagrid


I have a checkbox next to each record in a datagrid. I need
to grab the
CompID value of each record in GetCompIDs() but I'm not
getting anything.
I've disabled the viewstate on my datagrid.  Could this be
the cause?
Thanks.


<script runat="server">   
  Dim ordList As String = "" 

  Sub GetCompIDs(ByVal Source As Object, ByVal E As
EventArgs)
        Dim i As Integer
        For i = 0 To MyDataGrid.Items.Count - 1
            Dim dgItem As DataGridItem = MyDataGrid.Items(i)
            Dim cb As CheckBox =
CType(dgItem.FindControl("chk1"), CheckBox)
            If Not (cb Is Nothing) And cb.Checked Then
                ordList += dgItem.Cells(1).Text &
","
            End If
        Next i
        label1.Text = "You selected " &
Trim(ordList)        
    End Sub
</script>


		<aspataGrid
id="MyDataGrid"  
			runat="server" 
			EnableViewState="False"
			DataKeyField="CompID">
			
			<Columns>			
			<asp:TemplateColumn
HeaderText="Select">
                        <ItemTemplate>
                            <asp:Checkbox
id="chk1" Runat="server" />
                        </ItemTemplate>
                    </asp:TemplateColumn>            
                   
			<asp:BoundColumn DataField="CompID"
HeaderText="CompID" />  						
			<asp:BoundColumn DataField="Ticker"
HeaderText="Ticker" />						      
                </Columns>

		</aspataGrid&
gt;
	        	
		<asp:Button id="btnCompIDs" Text="Get
Comp IDs"
onclick="GetCompIDs" Runat="server"
/>
		<asp:Label ID="label1"
ForeColor="Blue" Runat="server"
/>



Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com


Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )