Data only populated on first page

Discussion in 'ASP .Net Datagrid Control' started by Mark, Jul 6, 2003.

  1. Mark

    Mark Guest

    I have a user control that I am using within a datagrid to display many
    instances of this control w/ paging.
    I'm using the DataBinder.Eval to set the properties of the control within
    the aspx page.
    ex. --> Description='<%#DataBinder.Eval(Container.DataItem,
    "description")%>'

    I have Autogeneratecolumns set to false because I don't want it to display
    the data in columns, I just need to set the data to properties of my
    control.

    Anyway, it works fine when the page loads, but when I change the page, the
    data doesn't get populated on the other pages.
    If I set the Autogenerate columns = true it works on every page. How do I
    get around not showing the columns, but still
    get the data?? Please help.

    thanks.
     
    Mark, Jul 6, 2003
    #1
    1. Advertising

  2. Make sure you're re-binding the data in your page index changed event.

    Datagrid Girl
    http://www.datagridgirl.com

    "Mark" <> wrote in message
    news:ufzdAo%...
    > I have a user control that I am using within a datagrid to display many
    > instances of this control w/ paging.
    > I'm using the DataBinder.Eval to set the properties of the control within
    > the aspx page.
    > ex. --> Description='<%#DataBinder.Eval(Container.DataItem,
    > "description")%>'
    >
    > I have Autogeneratecolumns set to false because I don't want it to

    display
    > the data in columns, I just need to set the data to properties of my
    > control.
    >
    > Anyway, it works fine when the page loads, but when I change the page, the
    > data doesn't get populated on the other pages.
    > If I set the Autogenerate columns = true it works on every page. How do I
    > get around not showing the columns, but still
    > get the data?? Please help.
    >
    > thanks.
    >
    >
     
    Datagrid Girl [MVP], Jul 7, 2003
    #2
    1. Advertising

  3. Mark

    Mark Guest

    HELP ME DATAGRID GIRL!!! :)

    Yes, I am rebinding the data on that event, the same as I am when I load the
    page, except I'm also setting the current page
    index also. Here's the code:

    public void Grid_Change(Object sender, DataGridPageChangedEventArgs e)
    {
    DataTable objDT;

    // Set CurrentPageIndex to the page the user clicked.

    dgMain.CurrentPageIndex = e.NewPageIndex;

    // Put user code to initialize the page here

    objDT=objExp.GetVerifiedItems();

    dgMain.DataSource = objDT;

    dgMain.DataBind();

    }


    "Datagrid Girl [MVP]" <> wrote in message
    news:...
    > Make sure you're re-binding the data in your page index changed event.
    >
    > Datagrid Girl
    > http://www.datagridgirl.com
    >
    > "Mark" <> wrote in message
    > news:ufzdAo%...
    > > I have a user control that I am using within a datagrid to display many
    > > instances of this control w/ paging.
    > > I'm using the DataBinder.Eval to set the properties of the control

    within
    > > the aspx page.
    > > ex. --> Description='<%#DataBinder.Eval(Container.DataItem,
    > > "description")%>'
    > >
    > > I have Autogeneratecolumns set to false because I don't want it to

    > display
    > > the data in columns, I just need to set the data to properties of my
    > > control.
    > >
    > > Anyway, it works fine when the page loads, but when I change the page,

    the
    > > data doesn't get populated on the other pages.
    > > If I set the Autogenerate columns = true it works on every page. How do

    I
    > > get around not showing the columns, but still
    > > get the data?? Please help.
    > >
    > > thanks.
    > >
    > >

    >
    >
     
    Mark, Jul 7, 2003
    #3
  4. bind the data on page load also.it may solve your problem.dont check
    IsPostBack etc.

    Rajesh

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Rajesh Tiwari, Jul 7, 2003
    #4
  5. Mark

    Mark Guest

    I was already doing that, but I tried NOT doing it on load and still the
    same result. This has to be a bug. It makes no sense that it would work when
    the page initially loads, but then won't work when you change pages.

    Just create a simple user control with one label on it, add a property
    (Caption) to the user control and put it in a datagrid like below. You'll
    see what I mean.

    <asp:datagrid id="dgMain" runat="server" Width="95%" Font-Names="Arial"
    Font-Size="Smaller" BorderStyle="None"
    BorderWidth="2px" GridLines="None" AllowSorting="True" CellSpacing="2"
    CellPadding="1" AllowPaging="True"
    OnPageIndexChanged="Grid_Change" PageSize="3"
    AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateColumn>
    <ItemStyle Width="80px"></ItemStyle>
    <ItemTemplate>
    <uc1:testcontrol id="Testcontrol1" runat="server" Caption='<%#
    DataBinder.Eval(Container.DataItem, "screenname") %>'>
    </uc1:testcontrol><br>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    <PagerStyle BorderWidth="2px" Font-Size="X-Small" Font-Names="Arial"
    BorderColor="#404040" BorderStyle="None"
    ForeColor="#0000C0" Position="TopAndBottom" BackColor="Silver"
    Mode="NumericPages"></PagerStyle>
    </asp:datagrid>




    "Rajesh Tiwari" <> wrote in message
    news:...
    > bind the data on page load also.it may solve your problem.dont check
    > IsPostBack etc.
    >
    > Rajesh
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Mark, Jul 7, 2003
    #5
  6. yes i agree with you.i also feel it is a bug.but the problem is that it
    is not consistent.i have used datagrid paging almost on 15 modules and
    it did not work in one or two.the problem narrowed to the fact that the
    EventHandler that is to be called on OnPageIndexChanged is not called
    when page index is changed and it leads to all the problems.but i have
    still to discover why it happens only in few cases.i am also giving a
    sample code which is showing this problem,may be someone may find what
    is wrong with this code and clarify our doubts.

    <%@ page Language="C#" debug=true %>
    <%@ Import namespace="System.Data"%>
    <%@ Import namespace="System.Data.SqlClient"%>
    <script language="C#" runat=server>
    SqlConnection con;
    void Page_Load(Object sender,EventArgs e)
    {
    con=new SqlConnection("Server=rajesh;database=test;uid=sa;pwd=sa");
    if(!IsPostBack)
    BindGrid();
    }
    public void DataGrid_Page(Object s,DataGridPageChangedEventArgs p)
    {
    grd.CurrentPageIndex=p.NewPageIndex;
    BindGrid();

    }
    public void BindGrid()
    {
    SqlDataAdapter adpt=new SqlDataAdapter("select * from author",con);
    DataSet dt=new DataSet();
    adpt.Fill(dt,"abcd");
    grd.DataSource=dt.Tables["abcd"].DefaultView;
    grd.DataBind();
    }
    </script>
    <html>
    <body>
    <form id=frm1 runat=server>
    <asp:datagrid id=grd AllowPaging="True" PageSize="1"
    PagerStyle-Mode="NumericPages"
    OnPageIndexChanged="DataGrid_Page"
    AutoGenerateColumns="true"
    runat=server
    >

    </asp:datagrid>
    </form>
    </body>
    </html>


    Rajesh

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Rajesh Tiwari, Jul 8, 2003
    #6
    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. =?Utf-8?B?ZG9ubmV0?=
    Replies:
    2
    Views:
    895
    =?Utf-8?B?ZG9ubmV0?=
    Feb 22, 2005
  2. GSN Sarma via .NET 247

    Another user's data is populated in my page

    GSN Sarma via .NET 247, May 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    409
    Mark Rae
    May 22, 2005
  3. madfisher

    Obtain Data from Populated Repeater

    madfisher, Feb 9, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    391
    Karl Seguin [MVP]
    Feb 9, 2006
  4. Accelerator
    Replies:
    1
    Views:
    477
    Ray Booysen
    Mar 20, 2006
  5. mark4asp
    Replies:
    0
    Views:
    285
    mark4asp
    Dec 19, 2006
Loading...

Share This Page