finding a checked box in a gridview

C

Carlos

Hi all,

I have a page that inherits from a master page and it contains a gridview
with a checkbox as a field.
My problem is that when I check the box it is not
detected correctly by my code. I know that I can
find it, but it reports checked as false all the time,
regardless of when it should report true.

i.e. in the gridviw I have:

<Columns>

<asp:BoundField DataField="EquipmentId" HeaderText="Equipment Id" />

<asp:TemplateField HeaderText="Receive">

<ItemStyle HorizontalAlign="Center" Font-Bold="True" Font-Names="Arial
Unicode MS" Font-Size="X-Small" VerticalAlign="Middle" />

<ItemTemplate>

<asp:CheckBox ID="chkSelect" runat="server" />

</ItemTemplate>

<HeaderStyle Font-Bold="True" Font-Names="Arial Unicode MS"
Font-Size="X-Small" BackColor="DarkGreen" HorizontalAlign="Left"
VerticalAlign="Middle" Width="40px" Wrap="False" />

</asp:TemplateField>



</Columns>

And my code behind

Dim chk As CheckBox

For Each rowItem As GridViewRow In GV_RecEquip.Rows

chk = CType(rowItem.Cells(0).FindControl("chkSelect"), CheckBox)

If chk.Checked = True Then

'do something

end if



End If


Next


Can someone help? Thanks!
 
E

Eliyahu Goldin

When (in what event) does your code run?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://blogs.microsoft.co.il/blogs/egoldin
http://msmvps.com/blogs/egoldin


Carlos said:
Hi all,

I have a page that inherits from a master page and it contains a gridview
with a checkbox as a field.
My problem is that when I check the box it is not
detected correctly by my code. I know that I can
find it, but it reports checked as false all the time,
regardless of when it should report true.

i.e. in the gridviw I have:

<Columns>

<asp:BoundField DataField="EquipmentId" HeaderText="Equipment Id" />

<asp:TemplateField HeaderText="Receive">

<ItemStyle HorizontalAlign="Center" Font-Bold="True" Font-Names="Arial
Unicode MS" Font-Size="X-Small" VerticalAlign="Middle" />

<ItemTemplate>

<asp:CheckBox ID="chkSelect" runat="server" />

</ItemTemplate>

<HeaderStyle Font-Bold="True" Font-Names="Arial Unicode MS"
Font-Size="X-Small" BackColor="DarkGreen" HorizontalAlign="Left"
VerticalAlign="Middle" Width="40px" Wrap="False" />

</asp:TemplateField>



</Columns>

And my code behind

Dim chk As CheckBox

For Each rowItem As GridViewRow In GV_RecEquip.Rows

chk = CType(rowItem.Cells(0).FindControl("chkSelect"), CheckBox)

If chk.Checked = True Then

'do something

end if



End If


Next


Can someone help? Thanks!


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4656 (20091202) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4656 (20091202) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

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,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top