Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2004, 01:40 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid Paging Problem

Currently I have a form which prompt to user select multiple display columns for the datagrid, and datagrid will be populated, using Itemplate to generate column dynamically, once user submit their selections. I need to implement paging, and in my case, datagrid's default paging feature is good enough. But here is the problem. According to the book, I just need to specify CurrentPageIndex = e.NewPageIndex with in the PageIndexChanged function, but that doesn't seem to work. If I have the BindData at page load then default paging works correctly, but user needs to specify the criteria first, and that happen before the page performs postback.
following is my code, can anyone give me a hint as to what I missed?



       private void Page_Load(object sender, System.EventArgs e)

      {

         // Put user code to initialize the page here

       }



       private void btn_Click(object sender, System.EventArgs e)

        {

            BindData();

        }



        private void BindData()

        {

            string cmdTxt = "Select num, title, acronym, comment from View";

            DataSet ds = SQLHelper.ExecuteDataSet(cmdTxt);

            foreach(DataColumn dc in ds.Tables[0].Columns)

            {

                dg.Columns.Add(DynamicColumns(dc.ColumnName));

            }

            dg.DataSource = ds.Tables[0];

            dg.DataBind();

        }



        protected TemplateColumn DynamicColumns(string column)

        {

            TemplateColumn genericcolumn = new TemplateColumn();

            genericcolumn.HeaderText = column;

            genericcolumn.ItemTemplate = new ItemColumnTemplate(column);

            return genericcolumn;

        }



        private void dg_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)

        {

            dg.CurrentPageIndex = e.NewPageIndex;

            BindData();

        }
 
Old March 2nd, 2004, 06:13 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

you have to select page index in these lines


      private void btn_Click(object sender, System.EventArgs e)

        {
            dg.CurrentPageIndex =0
            BindData();

        }

Ahmed Ali
Software Developer
 
Old March 2nd, 2004, 12:05 PM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply, but I don't think I explained my problem quite right. The problem is that the way I am setting up my page, user submit the random selected categories from web form and populate the datagrid, which does show correctly. However, when user trying to do paging by selecting 2nd or any other page, the datagrid itself will disappear entirely.

All the paging example I found had the following

     private void Page_Load(object sender, System.EventArgs e)
    {
         if(!IsPostBack)
         {
            BindData()
         }
     }

But this does not work in my situation, I have to show the form first and then show the grid after submit. Using AutoGenerateColumns="True" does solve this problem, but then I have no way of setting the columns to show hyperlink or images dynamically. Can anyone help with this problem?





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Paging Problem hoailing22 ASP.NET 1.0 and 1.1 Basics 5 April 23rd, 2006 03:15 AM
Problem in Paging in Datagrid Rahul Gupta ASP.NET 1.0 and 1.1 Basics 0 December 16th, 2005 07:58 AM
DataGrid Paging Problem! zakaria ASP.NET 1.0 and 1.1 Basics 1 April 8th, 2005 06:12 PM
Problem in dataGrid Paging Baby_programmer ASP.NET 1.0 and 1.1 Professional 2 February 23rd, 2005 08:47 PM
Paging problem with datareader and datagrid alyeng2000 ASP.NET 1.0 and 1.1 Basics 4 September 9th, 2004 02:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.