Solved

DataGridPageChangedEventHandler not firing

Posted on 2006-06-27
3
394 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

930 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

12 Experts available now in Live!

Get 1:1 Help Now