GridView Blank with AllowPaging="True"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Wood

    GridView Blank with AllowPaging="True"

    Okay, I spent about 3 hours getting the GridView control to do what I
    needed.

    Basically, I set the control's AutoGenerateCol umns to False and then defined
    a single template column (which I will customize with my own content). This
    looks something like this:

    <asp:GridView ID="GridView1" runat="server" CellPadding="4"
    ForeColor="#333 333" GridLines="None " AutoGenerateCol umns="False"
    Width="100%" AllowPaging="Fa lse"
    OnPageIndexChan ged="GridView1_ PageIndexChange d">
    <Columns>
    <asp:TemplateFi eld HeaderText="Art icles">
    <ItemTemplate >
    <b><%# Eval("art_name" ) %></b><br />
    <%# Eval("art_desc" ) %>
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>

    Then, in my page's Load event, I run a database query and do something like
    this:

    SqlDataReader reader = cmd.ExecuteRead er();
    GridView1.DataS ource = reader;
    GridView1.DataB ind();
    reader.Close();

    I finally got it working. However, when I set the AllowPaging property to
    True, then the grid displays absolutely nothing on the Web page. (It looks
    fine in the IDE.)

    I even tried running a new query and re-executing the lines above in
    response to the control's PageIndexChange d event but that doesn't help.

    Does anyone have any ideas?

    Thanks!

    --
    Jonathan Wood
    SoftCircuits Programming



  • Eliyahu Goldin

    #2
    Re: GridView Blank with AllowPaging=&qu ot;True&quot;

    Jonathan,

    I guess the problem is in using a SqlDataReader as a datasource. The msdn
    library states that "the paging feature can be used with any data source
    object that supports the System.Collecti ons.ICollection interface or a data
    source that supports paging capability". SqlDataReader is neither of them.
    An example of a data source that supports paging capability is
    SqlDataSource.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]




    "Jonathan Wood" <jwood@softcirc uits.comwrote in message
    news:%23nybqO4Q HHA.1860@TK2MSF TNGP06.phx.gbl. ..
    Okay, I spent about 3 hours getting the GridView control to do what I
    needed.
    >
    Basically, I set the control's AutoGenerateCol umns to False and then
    defined a single template column (which I will customize with my own
    content). This looks something like this:
    >
    <asp:GridView ID="GridView1" runat="server" CellPadding="4"
    ForeColor="#333 333" GridLines="None " AutoGenerateCol umns="False"
    Width="100%" AllowPaging="Fa lse"
    OnPageIndexChan ged="GridView1_ PageIndexChange d">
    <Columns>
    <asp:TemplateFi eld HeaderText="Art icles">
    <ItemTemplate >
    <b><%# Eval("art_name" ) %></b><br />
    <%# Eval("art_desc" ) %>
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
    >
    Then, in my page's Load event, I run a database query and do something
    like this:
    >
    SqlDataReader reader = cmd.ExecuteRead er();
    GridView1.DataS ource = reader;
    GridView1.DataB ind();
    reader.Close();
    >
    I finally got it working. However, when I set the AllowPaging property to
    True, then the grid displays absolutely nothing on the Web page. (It looks
    fine in the IDE.)
    >
    I even tried running a new query and re-executing the lines above in
    response to the control's PageIndexChange d event but that doesn't help.
    >
    Does anyone have any ideas?
    >
    Thanks!
    >
    --
    Jonathan Wood
    SoftCircuits Programming

    >
    >

    Comment

    • Mark Rae

      #3
      Re: GridView Blank with AllowPaging=&qu ot;True&quot;

      "Jonathan Wood" <jwood@softcirc uits.comwrote in message
      news:%23nybqO4Q HHA.1860@TK2MSF TNGP06.phx.gbl. ..
      I finally got it working. However, when I set the AllowPaging property to
      True, then the grid displays absolutely nothing on the Web page. (It looks
      fine in the IDE.)
      >
      I even tried running a new query and re-executing the lines above in
      response to the control's PageIndexChange d event but that doesn't help.
      >
      Does anyone have any ideas?
      You're using an SqlDataReader as the DataSource - can't do that if you want
      paging.

      Use a DataSet instead and all will be well.


      Comment

      • Jonathan Wood

        #4
        Re: GridView Blank with AllowPaging=&qu ot;True&quot;

        That must be it. Thanks.

        --
        Jonathan Wood
        SoftCircuits Programming


        "Eliyahu Goldin" <REMOVEALLCAPIT ALSeEgGoldDinN@ mMvVpPsS.orgwro te in
        message news:uOXcqZ4QHH A.3996@TK2MSFTN GP04.phx.gbl...
        Jonathan,
        >
        I guess the problem is in using a SqlDataReader as a datasource. The msdn
        library states that "the paging feature can be used with any data source
        object that supports the System.Collecti ons.ICollection interface or a
        data source that supports paging capability". SqlDataReader is neither of
        them. An example of a data source that supports paging capability is
        SqlDataSource.
        >
        --
        Eliyahu Goldin,
        Software Developer & Consultant
        Microsoft MVP [ASP.NET]


        >
        >
        "Jonathan Wood" <jwood@softcirc uits.comwrote in message
        news:%23nybqO4Q HHA.1860@TK2MSF TNGP06.phx.gbl. ..
        >Okay, I spent about 3 hours getting the GridView control to do what I
        >needed.
        >>
        >Basically, I set the control's AutoGenerateCol umns to False and then
        >defined a single template column (which I will customize with my own
        >content). This looks something like this:
        >>
        ><asp:GridVie w ID="GridView1" runat="server" CellPadding="4"
        >ForeColor="#33 3333" GridLines="None " AutoGenerateCol umns="False"
        >Width="100%" AllowPaging="Fa lse"
        >OnPageIndexCha nged="GridView1 _PageIndexChang ed">
        ><Columns>
        > <asp:TemplateFi eld HeaderText="Art icles">
        > <ItemTemplate >
        > <b><%# Eval("art_name" ) %></b><br />
        > <%# Eval("art_desc" ) %>
        > </ItemTemplate>
        > </asp:TemplateFie ld>
        ></Columns>
        ></asp:GridView>
        >>
        >Then, in my page's Load event, I run a database query and do something
        >like this:
        >>
        >SqlDataReade r reader = cmd.ExecuteRead er();
        >GridView1.Data Source = reader;
        >GridView1.Data Bind();
        >reader.Close() ;
        >>
        >I finally got it working. However, when I set the AllowPaging property to
        >True, then the grid displays absolutely nothing on the Web page. (It
        >looks fine in the IDE.)
        >>
        >I even tried running a new query and re-executing the lines above in
        >response to the control's PageIndexChange d event but that doesn't help.
        >>
        >Does anyone have any ideas?
        >>
        >Thanks!
        >>
        >--
        >Jonathan Wood
        >SoftCircuits Programming
        >http://www.softcircuits.com
        >>
        >>
        >
        >

        Comment

        • Jonathan Wood

          #5
          Re: GridView Blank with AllowPaging=&qu ot;True&quot;

          I'll look into using a DataSet instead.

          Thanks.

          --
          Jonathan Wood
          SoftCircuits Programming


          "Mark Rae" <mark@markNOSPA Mrae.comwrote in message
          news:%23Z4Lyr4Q HHA.5032@TK2MSF TNGP03.phx.gbl. ..
          "Jonathan Wood" <jwood@softcirc uits.comwrote in message
          news:%23nybqO4Q HHA.1860@TK2MSF TNGP06.phx.gbl. ..
          >
          >I finally got it working. However, when I set the AllowPaging property to
          >True, then the grid displays absolutely nothing on the Web page. (It
          >looks fine in the IDE.)
          >>
          >I even tried running a new query and re-executing the lines above in
          >response to the control's PageIndexChange d event but that doesn't help.
          >>
          >Does anyone have any ideas?
          >
          You're using an SqlDataReader as the DataSource - can't do that if you
          want paging.
          >
          Use a DataSet instead and all will be well.
          >

          Comment

          Working...