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. DataGrid PageIndexChangedHandler not getting called

DataGrid PageIndexChangedHandler not getting called

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
4 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.
  • S Offline
    S Offline
    Sibi Mathews
    wrote on last edited by
    #1

    Hi all, I am facing a great problem with the Webcontrol DataGrids PageIndexChangedHandler is not getting Called. I am creating a DropDownList and a DataGrid Dynamically. The DropDownLists AutoPostBack=true. On selecting an Item in the Dropdownlist PostBack happens and Dropdownlists SelectionChanged handler gets called where the Query is fired to Database and the DataSet is assigned to DataGrid and its DataBind() is called. But the problem lies here, when you click the page index of DataGrid. The code never runs into the PageIndexChange Handler of the DataGrid. It runs through the Page_Load() and comes out. What may be the problem? Please help me out.

    N 1 Reply Last reply
    0
    • S Sibi Mathews

      Hi all, I am facing a great problem with the Webcontrol DataGrids PageIndexChangedHandler is not getting Called. I am creating a DropDownList and a DataGrid Dynamically. The DropDownLists AutoPostBack=true. On selecting an Item in the Dropdownlist PostBack happens and Dropdownlists SelectionChanged handler gets called where the Query is fired to Database and the DataSet is assigned to DataGrid and its DataBind() is called. But the problem lies here, when you click the page index of DataGrid. The code never runs into the PageIndexChange Handler of the DataGrid. It runs through the Page_Load() and comes out. What may be the problem? Please help me out.

      N Offline
      N Offline
      NekChan
      wrote on last edited by
      #2

      1, View the cs code, confirm that you have created the PageIndexChanged function; 2, Did you call the function in 'private void InitializeComponent()' No pains, no gains.

      S 1 Reply Last reply
      0
      • N NekChan

        1, View the cs code, confirm that you have created the PageIndexChanged function; 2, Did you call the function in 'private void InitializeComponent()' No pains, no gains.

        S Offline
        S Offline
        Sibi Mathews
        wrote on last edited by
        #3

        I have the PageIndexChanged function in my cs code. And since I am creating the controls in the Page_Load() I cannot call the function in InitializeComponent. But now I found something else when the DataGrid is Populated on Page_Load itself the Paging works but when it is populated on Dropdownlist Selection Handler DataGrid Paging doesn't work. Here is my cs code....Please help me.... protected System.Web.UI.HtmlControls.HtmlForm Form1; //Object of the form same as form id in html private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=10.0.0.245;Initial Catalog=Sibi;User Id=sa;Password=sa"); SqlDataAdapter adpt = new SqlDataAdapter("Select * from Login",conn); DataSet ds = new DataSet(); adpt.Fill(ds); DropDownList drplst = new DropDownList(); //Dropdownlist is created drplst.ID = "drplst"; drplst.AutoPostBack = true; drplst.SelectedIndexChanged +=new EventHandler (this.drplst_SelectedIndexChanged); drplst.Items.Add("Green"); drplst.Items.Add("Blue"); drplst.Items.Add("Red"); Form1.Controls.Add(drplst); DataGrid dgrid = new DataGrid(); //DataGrid is Created dgrid.ID = "dgrid"; dgrid.PageIndexChanged +=new DataGridPageChangedEventHandler(this.dgrid_PageIndexChanged); dgrid.AllowPaging = true; dgrid.PagerStyle.Mode = PagerMode.NumericPages; dgrid.PageSize = 2; Form1.Controls.Add(dgrid); dgrid.AutoGenerateColumns = false; BoundColumn name = new BoundColumn(); name.HeaderText = "NAME"; name.DataField = "Name"; dgrid.Columns.Add(name); BoundColumn Id = new BoundColumn(); Id.HeaderText = "Id"; Id.DataField = "Id"; dgrid.Columns.Add(Id); ViewState["DS"] = ds; } private void dgrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DataGrid dgrid = (DataGrid)Form1.FindControl("dgrid"); dgrid.CurrentPageIndex = e.NewPageIndex; dgrid.DataSource = (DataSet)ViewState["DS"]; dgrid.DataBind(); } private void drplst_SelectedIndexChanged(object sender, System.EventArgs e) { DataGrid dgrid = (DataGrid)Form1.FindControl("dgrid"); dgrid.DataSource = (DataSet)ViewState["DS"]; dgrid.DataBind(); }

        N 1 Reply Last reply
        0
        • S Sibi Mathews

          I have the PageIndexChanged function in my cs code. And since I am creating the controls in the Page_Load() I cannot call the function in InitializeComponent. But now I found something else when the DataGrid is Populated on Page_Load itself the Paging works but when it is populated on Dropdownlist Selection Handler DataGrid Paging doesn't work. Here is my cs code....Please help me.... protected System.Web.UI.HtmlControls.HtmlForm Form1; //Object of the form same as form id in html private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=10.0.0.245;Initial Catalog=Sibi;User Id=sa;Password=sa"); SqlDataAdapter adpt = new SqlDataAdapter("Select * from Login",conn); DataSet ds = new DataSet(); adpt.Fill(ds); DropDownList drplst = new DropDownList(); //Dropdownlist is created drplst.ID = "drplst"; drplst.AutoPostBack = true; drplst.SelectedIndexChanged +=new EventHandler (this.drplst_SelectedIndexChanged); drplst.Items.Add("Green"); drplst.Items.Add("Blue"); drplst.Items.Add("Red"); Form1.Controls.Add(drplst); DataGrid dgrid = new DataGrid(); //DataGrid is Created dgrid.ID = "dgrid"; dgrid.PageIndexChanged +=new DataGridPageChangedEventHandler(this.dgrid_PageIndexChanged); dgrid.AllowPaging = true; dgrid.PagerStyle.Mode = PagerMode.NumericPages; dgrid.PageSize = 2; Form1.Controls.Add(dgrid); dgrid.AutoGenerateColumns = false; BoundColumn name = new BoundColumn(); name.HeaderText = "NAME"; name.DataField = "Name"; dgrid.Columns.Add(name); BoundColumn Id = new BoundColumn(); Id.HeaderText = "Id"; Id.DataField = "Id"; dgrid.Columns.Add(Id); ViewState["DS"] = ds; } private void dgrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DataGrid dgrid = (DataGrid)Form1.FindControl("dgrid"); dgrid.CurrentPageIndex = e.NewPageIndex; dgrid.DataSource = (DataSet)ViewState["DS"]; dgrid.DataBind(); } private void drplst_SelectedIndexChanged(object sender, System.EventArgs e) { DataGrid dgrid = (DataGrid)Form1.FindControl("dgrid"); dgrid.DataSource = (DataSet)ViewState["DS"]; dgrid.DataBind(); }

          N Offline
          N Offline
          NekChan
          wrote on last edited by
          #4

          Pls see the code: protected System.Web.UI.HtmlControls.HtmlForm Form1; private void Page_Load(object sender, System.EventArgs e) { SetTempData(); DataGrid dgrid = new DataGrid(); //DataGrid is Created dgrid.ID = "dgrid"; dgrid.PageIndexChanged += new DataGridPageChangedEventHandler(this.dgrid_PageIndexChanged); dgrid.AllowPaging = true; dgrid.PagerStyle.Mode = PagerMode.NumericPages; dgrid.PageSize = 2; Form1.Controls.Add(dgrid); dgrid.AutoGenerateColumns = false; BoundColumn name = new BoundColumn(); name.HeaderText = "Name"; name.DataField = "Name"; dgrid.Columns.Add(name); BoundColumn Id = new BoundColumn(); Id.HeaderText = "ID"; Id.DataField = "ID"; dgrid.Columns.Add(Id); dgrid.DataSource = ((DataTable)ViewState["DT"]).DefaultView; dgrid.DataBind(); } private void dgrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { DataGrid dgrid = (DataGrid)Form1.FindControl("dgrid"); dgrid.CurrentPageIndex = e.NewPageIndex; dgrid.DataSource = ((DataTable)ViewState["DT"]).DefaultView; dgrid.DataBind(); } private void SetTempData() { DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(String)); dt.Columns.Add("Name", typeof(String)); DataRow dr; for (int i=0; i<100; i++) { dr = dt.NewRow(); dr["ID"] = i.ToString("000"); dr["Name"] = "Name" + i.ToString("000"); dt.Rows.Add(dr); } ViewState["DT"] = dt; } No pains, no gains.

          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