loop through checkbox's in a datagridview on an asp.net applicaiton c# or vb.net

OK, i have two issues

1. For some reason my checkbox is not appearing in the grid.
2. Once the checkbox appears how do i loop through all itmes in teh grid and check the status of the checkbox.

The datasource does not have a Boolean field bound to the grid.
 
Dim sql As String = _
            "Select LastName, FirstName, EmailAddress FROM RegisteredUsers"
        cmdSQL.CommandText = sql
 
        Dim dsRegisteredUsers As DataSet = objData.QueryDataset(cmdSQL, "RegisteredUsers")
'Query dataset is a function that gets my dataset based off the query
 
 
        Me.GridView1.DataSource = dsRegisteredUsers
        Me.GridView1.DataMember = "RegisteredUsers"
        Me.GridView1.DataBind()
 
 
'' Here is my markup
 
                <asp:GridView  
                    ID="GridView1" runat="server"
                    BackColor="#99FF99" BorderColor="#000066">
                        <Columns>
                         <asp:CheckBoxField HeaderText="Select" />
                         <asp:BoundField DataField="LastName" HeaderText="Last Name" 
                                SortExpression="LastName" >
                                <ItemStyle Width="120px" />
                          </asp:BoundField> 
                          <asp:BoundField DataField="FirstName" HeaderText="First Name" 
                                SortExpression="FirstName" >
                                <ItemStyle Width="120px" />
                          </asp:BoundField> 
                          <asp:BoundField DataField="EmailAddress" HeaderText="Email Address" 
                                SortExpression="EmailAddress" >
                                <ItemStyle Width="200px" />
                          </asp:BoundField>        
                        </Columns>
                     <HeaderStyle BackColor="#3399FF" />
                     <AlternatingRowStyle BackColor="#FFFF99" />
                </asp:GridView>

Open in new window

LVL 7
talker2004Asked:
Who is Participating?
 
3abqariCommented:
Yeah, the Page.IsPostBack is something that you have to keep track of in web development...
0
 
3abqariCommented:
Have you tried to use the ItemDataBound Event of the gridview?
0
 
burakiewiczCommented:
and try this for the checkbox
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>&nbsp;
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
burakiewiczCommented:
oops should be all this
<asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="chk" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>

Open in new window

0
 
burakiewiczCommented:
and for the loop
For Each gvr As GridViewRow In GridView1.Rows

Next
0
 
3abqariCommented:
You don't have to use the Loop if you use the ItemDataBound Event.  The code in the ItemDataBound Event gets executed for each row of the grid.

The loop would be useful outside of the ItemDataBound Event.  I just wanted to clear that up.
0
 
burakiewiczCommented:
3abqari:
probably should have mentioned that the loop would just be used for processing only after the ItemDataBound Event.
0
 
talker2004Author Commented:


i am real close, got the loop like you said
but i am not able to read the value of ?gvr.Cells(0)

how can you tell if the checkbox is checked?

0
 
3abqariCommented:
Try using the gvr.FindControl("chk")
0
 
3abqariCommented:
or ctype(gvr.FindControl("chk"), checkbox).checked
0
 
talker2004Author Commented:
sweet it looks good i am going to try it when i get home.

Is it just me or is ee having some issues with speed today?

0
 
3abqariCommented:
I'm using the Expert skin, which eliminates all the advertisement that are in the Premium skin...  It's fine here.
0
 
talker2004Author Commented:
is there any reason it would be coming up false when it's checked

and after the post backs all of my checks clear
0
 
3abqariCommented:
tell me exactly what you are trying to do with this grid so that I can maybe answer you?
0
 
talker2004Author Commented:
duh, i was binding the grid in the page load event and i did not have an IsPostBack condition.

it's working now, thanks so much.....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.