Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


DataGridPageChangedEventHandler not firing

Posted on 2006-06-27
Medium Priority
Last Modified: 2012-06-27
The code below is used to create a datagrid at runtime.
I am adding event handlers to control Paging and editcommand however neither of the event handlers are firing
any ideas?

  protected void loadGrids()
        foreach(DataListItem Item in this.DataList1.Items){

            //Create a new DataGrid object named QueuesDataGrid
            DataGrid QueuesDataGrid = new DataGrid();

            //Format the DataGrid to look cool.
            QueuesDataGrid.BorderWidth = (Unit)1;
            QueuesDataGrid.CellPadding = 4;
            QueuesDataGrid.CellSpacing = 0;
            QueuesDataGrid.GridLines = GridLines.Horizontal;
            QueuesDataGrid.BorderColor = Color.Black;
            QueuesDataGrid.AllowPaging = true;
            QueuesDataGrid.PageSize = 6;
            QueuesDataGrid.AllowSorting = false;

            QueuesDataGrid.ItemStyle.Font.Name = "Verdana";
            QueuesDataGrid.ItemStyle.Font.Size = FontUnit.XSmall;

            //QueuesDataGrid.AlternatingItemStyle.BackColor = Color.FromName("LightGray");

            QueuesDataGrid.ShowHeader = true;
            QueuesDataGrid.HeaderStyle.BackColor = Color.Black;
            QueuesDataGrid.HeaderStyle.ForeColor = Color.White;
            QueuesDataGrid.HeaderStyle.Font.Bold = true;
            QueuesDataGrid.HeaderStyle.Font.Size = FontUnit.XSmall;

            //Do not autogenerate columns.
            QueuesDataGrid.AutoGenerateColumns = false;

            //****Add a series of BoundColumns****//
            //***Payment Filename***//
            BoundColumn bc = new BoundColumn();
            ButtonColumn btnCol = new ButtonColumn();
            //Set the BoundColumn Values
            bc.HeaderText = "Filename";
            bc.DataField = "fileName";
            bc.ItemStyle.Wrap = false;
            //Add the BoundColumn to the QueuesDataGrid.

            bc = new BoundColumn();
            bc.HeaderText = "Priority";
            bc.DataField = "priority";
            bc.ItemStyle.Wrap = false;

            //***Edit Button***///
            btnCol = new ButtonColumn();
            btnCol.CommandName = "Edit";
            btnCol.Text = "Change Priority";
            btnCol.CommandName = "Edit";
            //****End BoundColumns****//

            //****Add Handlers****//
            QueuesDataGrid.PageIndexChanged += new DataGridPageChangedEventHandler(this.dg_PageIndexChanged);
            QueuesDataGrid.EditCommand += new DataGridCommandEventHandler(dg_EditCommand);

            //Get the queue DataView filtered for the Type of payment
            DataView _files = ((DataSet)this.Session["FILE_LIST"]).Tables["LIST"].DefaultView;
            _files.RowFilter = "type='" + ((Label)Item.FindControl("lblType")).Text + "'";

            //Bind the DataGrid.
            QueuesDataGrid.DataSource = _files;


            //Add the DataGrid to the Atlas collapsible panel.
            Control x = Item.FindControl("Panel1");


    public void dg_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
        ((DataGrid)sender).CurrentPageIndex = e.NewPageIndex;
Question by:Andy_Webster
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

dtryon earned 2000 total points
ID: 16993652
Where are you calling loadGrids() from?
In order to register events you sometimes have to wire them up higher in the page hierarchy.
In other words, are you calling the method in the Page_Load?
Try calling the method in the OnInit method.


Author Comment

ID: 16999359
Ah great thanks! that has got the event firing straight away!

Expert Comment

ID: 16999536

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question