Paging,Gridview is invisible

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zhshqzyc
    New Member
    • Feb 2008
    • 9

    Paging,Gridview is invisible

    Hi, I am using the paging skills for my page.
    I'm doing manual databinding (that is, setting the DataSource property, and then calling DataBind()) instead of automatic databinding. So I manually handle events for paging. But the page is invisible.
    Thanks for your help.

    Code:
    protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {
                
                DataSet myDataSet = new DataSet();
                GenerateDataSet(myDataSet);
    
                // databind the page 
                GridView1.DataSource = myDataSet.Tables["Weather"];
                GridView1.PageIndex = e.NewPageIndex;
                GridView1.DataBind();
            }
    
            void GenerateDataSet(DataSet dset)
            {
                AddTable(dset);
            }
    
            void AddTable(DataSet dset)
            {
                // create the table
                DataTable WeatherTable = new DataTable("Weather");
                DataColumn WeatherID = WeatherTable.Columns.Add("State", typeof(string));
                WeatherTable.Columns.Add("Division", typeof(String));
                WeatherTable.Columns.Add("Temp", typeof(string));
    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="First.aspx.cs" Inherits="FirstPage.GetStrings" %>
    <% @Import Namespace="My.Name.Space" %>
    <% @Import Namespace="My.Name.Space1" %>
    
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True">
            </asp:GridView>
        </div>
       
        </form>
    </body>
    </html>
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Are you dynamically adding columns to the gridview? If not you need to use DataBound columns within the Columns tag of the gridview and choose a datafield to bind the data to .

    Nathan

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Originally posted by zhshqzyc
      Hi, I am using the paging skills for my page.
      I'm doing manual databinding (that is, setting the DataSource property, and then calling DataBind()) instead of automatic databinding. So I manually handle events for paging. But the page is invisible.
      Thanks for your help.
      I would call THAT automatic databinding, as I don't see anything getting anymore automatic then that. I woulda said manual was when you create the columns and rows yourself.

      You seem to be doing a lot of extra work in your page event.
      This is what happens in my page index changing event:
      Code:
      //gvOverdueSites is my GridView object
      gvOverdueSites.PageIndex = e.NewPageIndex;
      gvOverdueSites.DataBind();
      I also set the datasource in the page_load() though.


      I see that you turned on the paging in the aspx code page, but didn't supply the rest of the info about it.
      Something like this maybe?
      [code=asp]
      <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue">
      <EmptyDataRowSt yle BackColor="Tran sparent" HorizontalAlign ="Center" />
      <PagerStyle BackColor="Yell ow" />
      <PagerSetting s Mode="NumericFi rstLast" />
      </asp:GridView>
      [/code]

      Comment

      • zhshqzyc
        New Member
        • Feb 2008
        • 9

        #4
        I just add
        Code:
        <EmptyDataRowStyle BackColor="Transparent"  HorizontalAlign="Center" />
                 <PagerStyle BackColor="Yellow" />
                 <PagerSettings Mode="NumericFirstLast" />
        It is still invisible.
        I got rid of "protected void Page_Load(objec t sender, EventArgs e)".
        Is it a cause?

        Could uou please directly point out what is wrong with my code?

        Regards!

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Well other then that your datasource seems to change everytime you request it. (You keep adding tables to it, never removing the old one) It looks workable, not sure why it goes invisible. Except that if you don't have the line in your aspx about what to do when it's empty, you might see that.

          Comment

          Working...