Solved

DataGridPageChangedEventHandler not firing

Posted on 2006-06-27
3
397 Views
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.
            QueuesDataGrid.Columns.Add(bc);

            //***Priority***//
            bc = new BoundColumn();
            bc.HeaderText = "Priority";
            bc.DataField = "priority";
            //bc.DataFormatString="{0:d}";
            bc.ItemStyle.Wrap = false;
            QueuesDataGrid.Columns.Add(bc);

            //***Edit Button***///
            btnCol = new ButtonColumn();
            btnCol.CommandName = "Edit";
            btnCol.Text = "Change Priority";
            btnCol.CommandName = "Edit";
            QueuesDataGrid.Columns.Add(btnCol);
           
            //****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;
            QueuesDataGrid.DataBind();

           

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

    }



    public void dg_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
    {
        ((DataGrid)sender).CurrentPageIndex = e.NewPageIndex;
        loadGrids();
    }
0
Comment
Question by:Andy_Webster
[X]
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
3 Comments
 
LVL 4

Accepted Solution

by:
dtryon earned 500 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.

0
 
LVL 2

Author Comment

by:Andy_Webster
ID: 16999359
Ah great thanks! that has got the event firing straight away!
0
 
LVL 4

Expert Comment

by:dtryon
ID: 16999536
Great!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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