Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Prob with paging

Prob with paging

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdata-structureshelpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amalatsliit
    wrote on last edited by
    #1

    In my asp.net project i use arraylist to add data to my datagrid.first i add my text box values to arraylist and then i set my arraylist to datagrid as a datasource.my code worked when i disable the paging of the datagrid. But when i enable the paging it gives error. Do I need to convert my array list into a dataset or dataview. Can any one provide me better solution? Thanks

    M 1 Reply Last reply
    0
    • A amalatsliit

      In my asp.net project i use arraylist to add data to my datagrid.first i add my text box values to arraylist and then i set my arraylist to datagrid as a datasource.my code worked when i disable the paging of the datagrid. But when i enable the paging it gives error. Do I need to convert my array list into a dataset or dataview. Can any one provide me better solution? Thanks

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      You basically can use ArrayList as a datasource of the DataGrid control. You can take a quick look at the BaseDataList.DataSource property[^] to see which object can be used as a datasource for the control. Could you be more specific about your error? And could you post a snippet of your sample code? Then we can try to help you figure out your problem here.

      A 1 Reply Last reply
      0
      • M minhpc_bk

        You basically can use ArrayList as a datasource of the DataGrid control. You can take a quick look at the BaseDataList.DataSource property[^] to see which object can be used as a datasource for the control. Could you be more specific about your error? And could you post a snippet of your sample code? Then we can try to help you figure out your problem here.

        A Offline
        A Offline
        amalatsliit
        wrote on last edited by
        #3

        Dear Mr.Minhpc thanks for the reply.any way this is the code which i use to add data to my grid. private void btnTaskAdd_Click(object sender, System.EventArgs e) { EPGTask = new EPGProjectTask(); EPGTask.EPGTProjID = txtProjID.Text.ToUpper(); EPGTask.EPGTPhaseID = txtPhaseID.Text.ToUpper(); EPGTask.EPGTPhaseName = txtPhaseDesc.Text.ToUpper(); EPGTask.EPGTTaskID = txtTaskID.Text.ToUpper(); EPGTask.EPGTDesc = txtTaskDesc.Text.ToUpper(); lstTask.Add(EPGTask); bindTaskDetails(); } private void bindTaskDetails() { foreach(DataGridItem item in DGTask.Items) { EPGTask = new EPGProjectTask(); //read the item template if(!item.ItemType.ToString().Equals("EditItem")) { EPGTask.EPGTProjID = ((Label)item.Cells[1].FindControl("lbl1")).Text; EPGTask.EPGTPhaseID= ((Label)item.Cells[2].FindControl("lbl2")).Text; EPGTask.EPGTPhaseName= ((Label)item.Cells[3].FindControl("lbl3")).Text; EPGTask.EPGTTaskID= ((Label)item.Cells[4].FindControl("lbl4")).Text; EPGTask.EPGTDesc= ((Label)item.Cells[5].FindControl("lbl5")).Text; } //read the edit item template else if(item.ItemType.ToString().Equals("EditItem")) { EPGTask.EPGTProjID= ((TextBox)item.Cells[1].FindControl("txt1")).Text; EPGTask.EPGTPhaseID= ((TextBox)item.Cells[2].FindControl("txt2")).Text; EPGTask.EPGTPhaseName = ((TextBox)item.Cells[3].FindControl("txt3")).Text; EPGTask.EPGTTaskID = ((TextBox)item.Cells[4].FindControl("txt4")).Text; EPGTask.EPGTDesc = ((TextBox)item.Cells[5].FindControl("txt5")).Text; } lstTask.Add(EPGTask); } DGTask.DataSource = lstTask; DGTask.DataBind(); } private void DGTask_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DGTask.CurrentPageIndex = e.NewPageIndex; }

        M 1 Reply Last reply
        0
        • A amalatsliit

          Dear Mr.Minhpc thanks for the reply.any way this is the code which i use to add data to my grid. private void btnTaskAdd_Click(object sender, System.EventArgs e) { EPGTask = new EPGProjectTask(); EPGTask.EPGTProjID = txtProjID.Text.ToUpper(); EPGTask.EPGTPhaseID = txtPhaseID.Text.ToUpper(); EPGTask.EPGTPhaseName = txtPhaseDesc.Text.ToUpper(); EPGTask.EPGTTaskID = txtTaskID.Text.ToUpper(); EPGTask.EPGTDesc = txtTaskDesc.Text.ToUpper(); lstTask.Add(EPGTask); bindTaskDetails(); } private void bindTaskDetails() { foreach(DataGridItem item in DGTask.Items) { EPGTask = new EPGProjectTask(); //read the item template if(!item.ItemType.ToString().Equals("EditItem")) { EPGTask.EPGTProjID = ((Label)item.Cells[1].FindControl("lbl1")).Text; EPGTask.EPGTPhaseID= ((Label)item.Cells[2].FindControl("lbl2")).Text; EPGTask.EPGTPhaseName= ((Label)item.Cells[3].FindControl("lbl3")).Text; EPGTask.EPGTTaskID= ((Label)item.Cells[4].FindControl("lbl4")).Text; EPGTask.EPGTDesc= ((Label)item.Cells[5].FindControl("lbl5")).Text; } //read the edit item template else if(item.ItemType.ToString().Equals("EditItem")) { EPGTask.EPGTProjID= ((TextBox)item.Cells[1].FindControl("txt1")).Text; EPGTask.EPGTPhaseID= ((TextBox)item.Cells[2].FindControl("txt2")).Text; EPGTask.EPGTPhaseName = ((TextBox)item.Cells[3].FindControl("txt3")).Text; EPGTask.EPGTTaskID = ((TextBox)item.Cells[4].FindControl("txt4")).Text; EPGTask.EPGTDesc = ((TextBox)item.Cells[5].FindControl("txt5")).Text; } lstTask.Add(EPGTask); } DGTask.DataSource = lstTask; DGTask.DataBind(); } private void DGTask_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DGTask.CurrentPageIndex = e.NewPageIndex; }

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          There are a couple of things come to mind: + You basically need to do two things in the event handler of the PageIndexChanged event of the DataGrid control:

          private void DGTask_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
          {
          //You first set the CurrentPageIndex property to the selected index.
          DGTask.CurrentPageIndex = e.NewPageIndex;

          //Then rebind the datasource to the DataGrid control to refresh the control.
          DGTask.DataSource = lstTask; 
          DGTask.DataBind(); 
          

          }

          For more information, see DataGrid.PageIndexChanged Event [^] + The way you populate the lstTask instance in the bindTaskDetails method looks strange to me, why not just save the lstTask object in Session then you can use it later when you want to get/add items of the arraylist.

          A 1 Reply Last reply
          0
          • M minhpc_bk

            There are a couple of things come to mind: + You basically need to do two things in the event handler of the PageIndexChanged event of the DataGrid control:

            private void DGTask_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
            {
            //You first set the CurrentPageIndex property to the selected index.
            DGTask.CurrentPageIndex = e.NewPageIndex;

            //Then rebind the datasource to the DataGrid control to refresh the control.
            DGTask.DataSource = lstTask; 
            DGTask.DataBind(); 
            

            }

            For more information, see DataGrid.PageIndexChanged Event [^] + The way you populate the lstTask instance in the bindTaskDetails method looks strange to me, why not just save the lstTask object in Session then you can use it later when you want to get/add items of the arraylist.

            A Offline
            A Offline
            amalatsliit
            wrote on last edited by
            #5

            Dear Mr.Minhpc thanks for the solution.but still i have same problem.i have added my arraylist to a session. This is the code which is in my bind method.... lstTask.Add(EPGTask); Session["TaskList"] = lstTask; ArrayList dd = new ArrayList(); dd = (ArrayList)Session["TaskList"]; DGTask.DataSource= dd; DGTask.DataBind(); this is in the pageindexpagechange..... DGTask.CurrentPageIndex = e.NewPageIndex; ArrayList dd = new ArrayList(); dd = (ArrayList)Session["TaskList"]; DGTask.DataSource= dd; DGTask.DataBind(); but when i add elements to grid,every time it shows only 1 element in the second page.and also i go to second page of my grid and try to add element then it gives error called ... Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount Please provide me better solution.

            M 1 Reply Last reply
            0
            • A amalatsliit

              Dear Mr.Minhpc thanks for the solution.but still i have same problem.i have added my arraylist to a session. This is the code which is in my bind method.... lstTask.Add(EPGTask); Session["TaskList"] = lstTask; ArrayList dd = new ArrayList(); dd = (ArrayList)Session["TaskList"]; DGTask.DataSource= dd; DGTask.DataBind(); this is in the pageindexpagechange..... DGTask.CurrentPageIndex = e.NewPageIndex; ArrayList dd = new ArrayList(); dd = (ArrayList)Session["TaskList"]; DGTask.DataSource= dd; DGTask.DataBind(); but when i add elements to grid,every time it shows only 1 element in the second page.and also i go to second page of my grid and try to add element then it gives error called ... Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount Please provide me better solution.

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Can you run your application in debug mode and try to see the values of the CurrentPageIndex and PageCount properties before the error happens? I doubt that those values are not inline with your datasource (the arraylist instance). If you just use a single web page for both listing all items and adding a new item, then you'll have to rebind the datasource to the datagrid so that it can reflect the updated datasource.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups