GridView.Rows empty on PostBack

Discussion in 'ASP .Net Datagrid Control' started by Doldrums, Feb 1, 2007.

  1. Doldrums

    Doldrums Guest

    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
    Doldrums, Feb 1, 2007
    #1
    1. Advertising

  2. Doldrums

    TiSch Guest

    On Feb 1, 8:04 am, Doldrums <>
    wrote:
    > 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
    TiSch, Feb 1, 2007
    #2
    1. Advertising

  3. Doldrums

    Doldrums Guest

    "TiSch" <> wrote in
    news::

    > 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
    Doldrums, Feb 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabio Mastria
    Replies:
    5
    Views:
    4,323
    TechMCAD13
    Jan 30, 2008
  2. Savvoulidis Iordanis

    Empty gridview cells and checking for empty string

    Savvoulidis Iordanis, Sep 5, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    506
    Savvoulidis Iordanis
    Sep 5, 2008
  3. VijayRama
    Replies:
    2
    Views:
    2,291
    Gregory A. Beamer
    Oct 12, 2009
  4. Gridview keeps adding rows when user causes postback

    , Oct 6, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    743
  5. Jéjé

    filling a gridview with empty rows?

    Jéjé, Jun 12, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    193
    Jéjé
    Jun 12, 2006
Loading...

Share This Page