Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

problem reading the status of a check box in a gridview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ma - 18 Sep 2007 22:51 GMT
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
Eliyahu Goldin - 19 Sep 2007 09:16 GMT
When do you do that? On the first page load or on postbacks? In what event?

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Hello,
>
[quoted text clipped - 39 lines]
>
> Regards
ma - 19 Sep 2007 15:46 GMT
Hello,
  There is a button on the page and I am doing this on the postback event
of this button.

Regards

> When do you do that? On the first page load or on postbacks? In what
> event?
[quoted text clipped - 42 lines]
>>
>> Regards
Eliyahu Goldin - 19 Sep 2007 16:27 GMT
Is ViewState enabled for the gridview?

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

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Hello,
>   There is a button on the page and I am doing this on the postback event
[quoted text clipped - 48 lines]
>>>
>>> Regards
ma - 19 Sep 2007 16:59 GMT
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

> Is ViewState enabled for the gridview?
>
[quoted text clipped - 53 lines]
>>>>
>>>> Regards

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.