Solved

DataGridPageChangedEventHandler not firing

Posted on 2006-06-27
3
393 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
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
dtryon earned 500 total points
Comment Utility
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
Comment Utility
Ah great thanks! that has got the event firing straight away!
0
 
LVL 4

Expert Comment

by:dtryon
Comment Utility
Great!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now