Accessing records from an Unbound gridview

1) I have a gridview which I bind dynamically in PageLoad by getting a dataset from an oracle stored procedure.
DataSet ds = new DataSet();  
ds = DBManager.getList();

DataView dv = new DataView(ds.Tables[0]);
        dgView.PageIndex = 0;
        dgView.DataSource = dv;
        Session.Add(Constants.DATAVIEW_TRADES, dv);

2) The grid view has a checkbox column for each row, the user can select (check) multiple rows and then hit the submit button, which has a onclick event.

 <asp:GridView ID="dgView" runat="server" DataKeyNames="CONFIRM_UUID" EnableViewState="true"   CssClass="align: top" RowStyle-Font-Size="XX-Small" Font-Size="XX-Small"
                                    AlternatingRowStyle-BackColor="LightSkyBlue" AllowPaging="True" Width="1100px" AutoGenerateColumns="False"
                                    AllowSorting="true"  EmptyDataRowStyle-Height="0" RowStyle-VerticalAlign="Top"  RowStyle-Height="4"
                                    OnPageIndexChanging="dgView_PageIndexChanging" AlternatingRowStyle-Height="5"   OnRowCommand="dg_RowCommand" OnSorting="dgView_Sorting">                                                                  
                                    <asp:Label runat="server"> There are no records found for the selected search criteria.
                                    <EmptyDataRowStyle Height="5" BackColor="LightSteelBlue" />
                                              <asp:TemplateField  HeaderText="Release">
                                                <HeaderStyle   BackColor="BlanchedAlmond" />
                                                    <asp:CheckBox ID="chkStatus"  Checked='<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "CHECKED_STATUS"))%>'  Visible="true"  
                                                    Enabled='<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "ENABLED_STATUS"))%>'  Font-Bold="true" runat="server" />                                                    

3) On the submit button click event, I need to retrieve all the rows that were checked on the gridview.
How can I do this with an unbounded gridview?
Who is Participating?
RossWilkoConnect With a Mentor Commented:

I believe this should be the sort of thing your looking for...  

  protected void Button1_Click(object sender, EventArgs e)
        foreach (GridViewRow dvItem in dgView.Rows)
            if (dvItem.RowType == DataControlRowType.DataRow)
                if (((CheckBox)dvItem.FindControl("chkStatus")).Checked)



countrymeisterAuthor Commented:
Hi ! RossWilko

I will try this first thing tomorrow morning, I left work a little early.
I will post my reply based on the solution you provided

countrymeisterAuthor Commented:
Works like a charm based on your reccomendation

Thanks, I do have another question extending on this solution which I hope you can help me.
I am going to add it as a new post.

Can I add a checkbox to the header of a checkbox column in a Grid View?
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.