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!
 
Ad

Advertisements

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
 

Top