GridView.Rows empty on PostBack

D

Doldrums

I have a GridView on my Asp.net page where I've added a TemplateField
that contains a CheckBox.

The idea is that a user can checkmark which records they want and then
click a "Submit" button. I want to take action in the PostBack for the
records that they selected.

My problem is that on the PostBack the GridView.Rows.Count = 0. Any
ideas how I am suppossed to read what checkboxes are checked?

-------

A little more information:
* AutoGenerateColumns="false".
* EnableSortingAndPagingCallbacks="false"... since I have a
TemplateField.
* I create the TemplateField in the aspx page.
* I create all other fields prior to DataBinding in the OnInit().
* GridView is bound to a SqlDataSource in the OnInit().
* I do NOT load or DataBind if the Page is a PostBack.
* Grid loads all the records fine when !Page.IsPostBack (44 Rows).
* I set a breakpoint in OnInit, PageLoad, and my Button_Click event.
The Rows are always = 0.

I've tried removing the TemplateField and setting
EnableSortingAndPagingCallbacks="true"... but still no luck.

I'm hoping my brain is just fried and I am missing something simple!

PLEASE help.

Thanks,

Hugh O'Donnell
 
T

TiSch

I have a GridView on my Asp.net page where I've added a TemplateField
that contains a CheckBox.

The idea is that a user can checkmark which records they want and then
click a "Submit" button. I want to take action in the PostBack for the
records that they selected.

My problem is that on the PostBack the GridView.Rows.Count = 0. Any
ideas how I am suppossed to read what checkboxes are checked?

-------

A little more information:
* AutoGenerateColumns="false".
* EnableSortingAndPagingCallbacks="false"... since I have a
TemplateField.
* I create the TemplateField in the aspx page.
* I create all other fields prior to DataBinding in the OnInit().
* GridView is bound to a SqlDataSource in the OnInit().
* I do NOT load or DataBind if the Page is a PostBack.
* Grid loads all the records fine when !Page.IsPostBack (44 Rows).
* I set a breakpoint in OnInit, PageLoad, and my Button_Click event.
The Rows are always = 0.

I've tried removing the TemplateField and setting
EnableSortingAndPagingCallbacks="true"... but still no luck.

I'm hoping my brain is just fried and I am missing something simple!

PLEASE help.

Thanks,

Hugh O'Donnell

Hi,
you could use javscript to write the id of the checked record into a
hiddenfield(comma separated).
Important: Use the onclick-Event not the onchange-Event because
ASP.NET generates a span and an input(type checkbox).
On codebehind you only have to read the hiddenfield to get the
selected records.

Regards,
Tim
 
D

Doldrums

Hi,
you could use javscript to write the id of the checked record into a
hiddenfield(comma separated).
Important: Use the onclick-Event not the onchange-Event because
ASP.NET generates a span and an input(type checkbox).
On codebehind you only have to read the hiddenfield to get the
selected records.

Regards,
Tim

Tim,

Thanks for the idea. I have thought of that... but my spec requires no
JavaScript... so I'm looking for an aspx solution.

I believe I *should* be able to read back from the GridView on PostBack.

Hugh
 

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

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top