GridView check all

M

Mike P

I am trying to add check all functionality to my grid view, but I can't
get it to work. Here is my gridview :

<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server"
ID="RowLevelCheckBox" />
</ItemTemplate>
</asp:TemplateField>

And here is the code, where Results is the name of my gridview :

protected void CheckAll_Click(object sender, EventArgs e)
{
foreach(GridViewRow gvr in Results.Rows)
//for (int i = 0; i < Results.Rows.Count; i++)
{
CheckBox chkBox =
(CheckBox)Results.FindControl("RowLevelCheckBox");

chkBox.Checked = true;
}
}

But I am getting the error 'object ref not set to instance of object' on
the line chkBox.Checked = true.

Can anybody help me out with this?

Thanks,

Mike
 
G

Guest

Replace

(CheckBox)Results.FindControl("RowLevelCheckBox");

with

(CheckBox)gvr.FindControl("RowLevelCheckBox");

and try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top