473,779 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:TemplateFi eld HeaderText="Sel ect">

<ItemTemplate >

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

</ItemTemplate>

</asp:TemplateFie ld>

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_Enterp rise_name.Rows. Count; i++)

{

GridViewRow row = GridView_Enterp rise_name.Rows[i];

bool isChecked =
((CheckBox)row. FindControl("ch kSelect")).Chec ked;

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 1882
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.com wrote in message
news:uF******** ********@TK2MSF TNGP04.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:TemplateFi eld HeaderText="Sel ect">

<ItemTemplate >

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

</ItemTemplate>

</asp:TemplateFie ld>

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_Enterp rise_name.Rows. Count; i++)

{

GridViewRow row = GridView_Enterp rise_name.Rows[i];

bool isChecked =
((CheckBox)row. FindControl("ch kSelect")).Chec ked;

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.orgwro te in
message news:ea******** ********@TK2MSF TNGP05.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.com wrote in message
news:uF******** ********@TK2MSF TNGP04.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:TemplateF ield HeaderText="Sel ect">

<ItemTemplat e>

<asp:CheckBo x ID="chkSelect" runat="server" />

</ItemTemplate>

</asp:TemplateFie ld>

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_Enterp rise_name.Rows. Count; i++)

{

GridViewRow row = GridView_Enterp rise_name.Rows[i];

bool isChecked =
((CheckBox)row .FindControl("c hkSelect")).Che cked;

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.com wrote in message
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
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.orgwro te in
message news:ea******** ********@TK2MSF TNGP05.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.com wrote in message
news:uF******* *********@TK2MS FTNGP04.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:Template Field HeaderText="Sel ect">

<ItemTemplate >

<asp:CheckB ox ID="chkSelect" runat="server" />

</ItemTemplate>

</asp:TemplateFie ld>

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_Enterp rise_name.Rows. Count; i++)

{

GridViewRow row = GridView_Enterp rise_name.Rows[i];

bool isChecked =
((CheckBox)ro w.FindControl(" chkSelect")).Ch ecked;

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.orgwro te in
message news:eE******** ********@TK2MSF TNGP03.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.com wrote in message
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
>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.orgwro te in
message news:ea******** ********@TK2MSF TNGP05.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.com wrote in message
news:uF****** **********@TK2M SFTNGP04.phx.gb l...
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:Templat eField HeaderText="Sel ect">

<ItemTemplat e>

<asp:CheckBo x ID="chkSelect" runat="server" />

</ItemTemplate>

</asp:TemplateFie ld>

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_Enterp rise_name.Rows. Count; i++)

{

GridViewRow row = GridView_Enterp rise_name.Rows[i];

bool isChecked =
((CheckBox)r ow.FindControl( "chkSelect")).C hecked;

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
3026
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 when reading out the data into the PHP variables / array. It should be displaying the information out in the following way, using the PHP array: n_date, n_headline, n_summarytext, n_fulltext
27
2607
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 in the changes document? John Roth
1
2765
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 -MyODBC 3.51
6
1780
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 handle it on my own. Right now the file is opened correctly and I'm able to read each line and print them in a new file. My problem is to insert each struct (which are made of 6 consecutive lines) as an item in my array.
1
3613
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 _ System.IO.StreamReader(Me.GetType.Assembly.GetManifestResourceStream("myname space.script.js")) I receive the error: Value cannot be null. Parameter name: stream I think the underlying problem is that the name of the assembly
0
1254
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 hundreds of messages in the queue, which I do not want to have processed by the async messagehandler at startup. So in Start(), I create a new thread, which's method just simply enums the queue-messages . At the end of this thread, I fire an...
4
3212
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
17211
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> <asp:TextBox ID="txtQty" runat="server" Width="29" Height="13" Text='<%# Eval("quantity") %>'></asp:TextBox>
1
1117
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% of the cases, the status bar returns blank. In my tests, both IE6 and IE7 works perfectly fine, in my development computer. But in production, with people coming from all over the world with who knows what funny software installed in their machine,...
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7478
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.