Link to home
Start Free TrialLog in
Avatar of Andy_Webster
Andy_Webster

asked on

DataGridPageChangedEventHandler not firing

 
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();
    }
ASKER CERTIFIED SOLUTION
Avatar of dtryon
dtryon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andy_Webster
Andy_Webster

ASKER

Ah great thanks! that has got the event firing straight away!
Great!