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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error Occurs while Paging in Datagrid!.......

Error Occurs while Paging in Datagrid!.......

Scheduled Pinned Locked Moved ASP.NET
helpquestion
2 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.
  • P Offline
    P Offline
    Prabs frm PGP
    wrote on last edited by
    #1

    Hi I want to do paging in the datalist. For that i wrote the code: public int intStart=0; private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { ViewState ["Start"]= 0; list(); } } public void list() { conn.Open(); SqlDataAdapter sda = new SqlDataAdapter("select name from sampledatagrid",conn); DataSet ds1 = new DataSet(); intStart = (int) ViewState["Start"]; ViewState ["PageSize"]=7; sda.Fill(ds1,intStart,(int)ViewState["PageSize"],"sampledatagrid"); dlistSample.DataSource=ds1.Tables[0].DefaultView; dlistSample.DataBind(); conn.Close(); } private void lnkPrevious_Click(object sender, System.EventArgs e) { intStart = (int) ViewState["Start"] -(int) ViewState["pageSize"]; ViewState["Start"] = intStart; if (intStart <= 0 ) { ViewState["Start"] = 0; } list(); } private void lnkNext_Click(object sender, System.EventArgs e) { int dlistcount = dlistSample.Items.Count; intStart = (int)ViewState["Start"] + (int)ViewState["pageSize"]; ViewState["Start"] = intStart; if ( dlistcount < (int)ViewState["pageSize"] ) { ViewState["Start"] = (int)ViewState["Start"] - (int)ViewState["pageSize"]; } list(); } } Here the values are displayed correctly in the Datalist., But If i cliks the Next or previus linkbutton(<< or >>) at the time it shows the error: Object reference not set to an instance of an object. Error occured in this line: intStart = (int)ViewState["Start"] + (int)ViewState["pageSize"]; How can we solve this one? Prabu.T

    V 1 Reply Last reply
    0
    • P Prabs frm PGP

      Hi I want to do paging in the datalist. For that i wrote the code: public int intStart=0; private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { ViewState ["Start"]= 0; list(); } } public void list() { conn.Open(); SqlDataAdapter sda = new SqlDataAdapter("select name from sampledatagrid",conn); DataSet ds1 = new DataSet(); intStart = (int) ViewState["Start"]; ViewState ["PageSize"]=7; sda.Fill(ds1,intStart,(int)ViewState["PageSize"],"sampledatagrid"); dlistSample.DataSource=ds1.Tables[0].DefaultView; dlistSample.DataBind(); conn.Close(); } private void lnkPrevious_Click(object sender, System.EventArgs e) { intStart = (int) ViewState["Start"] -(int) ViewState["pageSize"]; ViewState["Start"] = intStart; if (intStart <= 0 ) { ViewState["Start"] = 0; } list(); } private void lnkNext_Click(object sender, System.EventArgs e) { int dlistcount = dlistSample.Items.Count; intStart = (int)ViewState["Start"] + (int)ViewState["pageSize"]; ViewState["Start"] = intStart; if ( dlistcount < (int)ViewState["pageSize"] ) { ViewState["Start"] = (int)ViewState["Start"] - (int)ViewState["pageSize"]; } list(); } } Here the values are displayed correctly in the Datalist., But If i cliks the Next or previus linkbutton(<< or >>) at the time it shows the error: Object reference not set to an instance of an object. Error occured in this line: intStart = (int)ViewState["Start"] + (int)ViewState["pageSize"]; How can we solve this one? Prabu.T

      V Offline
      V Offline
      Vipin Venugopal
      wrote on last edited by
      #2

      on the pageindexchanged event of the datagrid write this code. DataGrid.CurrentPageIndex = e.NewPageIndex; after this line call the datagrid to load the contents again this will work fine. Vipin

      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