473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

problem reading the status of a check box in a gridview

ma
Hello,

I have a GrideView that has 4 col. 3 of them are bound to a dataset and
the last one is not. The last one is check box. The check box is defined as
follow:

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

I am trying to read the state of these checkbox using the folllwng code:

// Select the checkboxes from the GridView control

for (int i = 0; i < GridView_Enterprise_name.Rows.Count; i++)

{

GridViewRow row = GridView_Enterprise_name.Rows[i];

bool isChecked =
((CheckBox)row.FindControl("chkSelect")).Checked;

if (isChecked)

{

// do something

}

}

but the code doesn't work as isChecked is always false. What is the problem
and how can I solve it?

Regards
Sep 18 '07 #1
4 1868
When do you do that? On the first page load or on postbacks? In what event?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"ma" <ma@nowhere.comwrote in message
news:uF****************@TK2MSFTNGP04.phx.gbl...
Hello,

I have a GrideView that has 4 col. 3 of them are bound to a dataset and
the last one is not. The last one is check box. The check box is defined
as follow:

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

I am trying to read the state of these checkbox using the folllwng code:

// Select the checkboxes from the GridView control

for (int i = 0; i < GridView_Enterprise_name.Rows.Count; i++)

{

GridViewRow row = GridView_Enterprise_name.Rows[i];

bool isChecked =
((CheckBox)row.FindControl("chkSelect")).Checked;

if (isChecked)

{

// do something

}

}

but the code doesn't work as isChecked is always false. What is the
problem and how can I solve it?

Regards


Sep 19 '07 #2
ma
Hello,
There is a button on the page and I am doing this on the postback event
of this button.

Regards

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ea****************@TK2MSFTNGP05.phx.gbl...
When do you do that? On the first page load or on postbacks? In what
event?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"ma" <ma@nowhere.comwrote in message
news:uF****************@TK2MSFTNGP04.phx.gbl...
>Hello,

I have a GrideView that has 4 col. 3 of them are bound to a dataset
and the last one is not. The last one is check box. The check box is
defined as follow:

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

I am trying to read the state of these checkbox using the folllwng code:

// Select the checkboxes from the GridView control

for (int i = 0; i < GridView_Enterprise_name.Rows.Count; i++)

{

GridViewRow row = GridView_Enterprise_name.Rows[i];

bool isChecked =
((CheckBox)row.FindControl("chkSelect")).Checke d;

if (isChecked)

{

// do something

}

}

but the code doesn't work as isChecked is always false. What is the
problem and how can I solve it?

Regards



Sep 19 '07 #3
Is ViewState enabled for the gridview?

Make sure you are not re-loading the grid on every postback.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"ma" <ma@nowhere.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
Hello,
There is a button on the page and I am doing this on the postback event
of this button.

Regards

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ea****************@TK2MSFTNGP05.phx.gbl...
>When do you do that? On the first page load or on postbacks? In what
event?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"ma" <ma@nowhere.comwrote in message
news:uF****************@TK2MSFTNGP04.phx.gbl...
>>Hello,

I have a GrideView that has 4 col. 3 of them are bound to a dataset
and the last one is not. The last one is check box. The check box is
defined as follow:

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

I am trying to read the state of these checkbox using the folllwng code:

// Select the checkboxes from the GridView control

for (int i = 0; i < GridView_Enterprise_name.Rows.Count; i++)

{

GridViewRow row = GridView_Enterprise_name.Rows[i];

bool isChecked =
((CheckBox)row.FindControl("chkSelect")).Checked ;

if (isChecked)

{

// do something

}

}

but the code doesn't work as isChecked is always false. What is the
problem and how can I solve it?

Regards




Sep 19 '07 #4
ma
Thanks. The problem solved.
I set the datagride data source on page_load event and it seems that doing
this will reset the checkboxes. I used a ispostback and the problem solved
now.

Regards

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eE****************@TK2MSFTNGP03.phx.gbl...
Is ViewState enabled for the gridview?

Make sure you are not re-loading the grid on every postback.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"ma" <ma@nowhere.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
>Hello,
There is a button on the page and I am doing this on the postback event
of this button.

Regards

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ea****************@TK2MSFTNGP05.phx.gbl...
>>When do you do that? On the first page load or on postbacks? In what
event?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"ma" <ma@nowhere.comwrote in message
news:uF****************@TK2MSFTNGP04.phx.gbl.. .
Hello,

I have a GrideView that has 4 col. 3 of them are bound to a dataset
and the last one is not. The last one is check box. The check box is
defined as follow:

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

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

</ItemTemplate>

</asp:TemplateField>

I am trying to read the state of these checkbox using the folllwng
code:

// Select the checkboxes from the GridView control

for (int i = 0; i < GridView_Enterprise_name.Rows.Count; i++)

{

GridViewRow row = GridView_Enterprise_name.Rows[i];

bool isChecked =
((CheckBox)row.FindControl("chkSelect")).Checke d;

if (isChecked)

{

// do something

}

}

but the code doesn't work as isChecked is always false. What is the
problem and how can I solve it?

Regards




Sep 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
1
by: Boris Wilhelms | last post by:
Hello all, at first, sorry for my bad English, I’ll give my best  We have a strange problem reading Text- and VarChar-Fields. Our configuration: -Windows 2003 Server -MySQL Server 3.23.36...
6
by: The_Kingpin | last post by:
Hi again guys, I've decided to cut my project in section and I found it way easier like this. I'm having a little problem reading struct in a file though. I think after this I'll be able to...
1
by: Brad | last post by:
I'm having a problem reading a resource stream using the following syntax: Dim resStream As System.IO.TextReader = New _ ...
0
by: Manfred Braun | last post by:
Hi All, I have a problem reading queue-messages async. My QueueReader has a Start() and a Stop() method and if my app starts, it calls Start(). The problem is, that there are possibly several...
4
by: andreas.fabri | last post by:
I have a problem reading integers separated by commas with VC8 This program: ___________________________ // read.C #include <iostream> int main()
2
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I have the foll template field <asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="center"> <ItemTemplate> <%# Eval("quantity") %> </ItemTemplate> <EditItemTemplate>...
1
by: fischermx | last post by:
I have a JS that under certain event (on focus) reads the status bar from IE6 and IE7 and performs certain action. It works on most of the cases, but in the log of this application, I see like 30%...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.