This is a migrated thread and some comments may be shown as answers.

Events doesn't fire when creating grid in code behind

6 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Covertix
Top achievements
Rank 1
Covertix asked on 17 May 2012, 11:29 AM
Hi,

I create a Grid on server-side on button click event.
The grid has been created fine, but the mfunctionality of the grid doesn't work.

For example, I am trying to change page size, but the event isn't fired.
Here is my code:

 

 

 

protected void btnGenerate_Click(object sender, EventArgs e)

{

PopulateGrid();

}

protected void PopulateGrid()

{

GridPlaceHolder.Controls.Clear();

RadGrid GridReport = new RadGrid();

GridReport.GroupingSettings.CaseSensitive =

false;

GridReport.ID =

"GridReport";

GridReport.Skin =

"Gray";

GridReport.EnableViewState =

false;

GridReport.MasterTableView.EnableColumnsViewState =

false;

GridReport.Width =

Unit.Pixel(1413);

GridReport.Height =

Unit.Pixel(550);

GridReport.AllowPaging =

true;

GridReport.AllowSorting =

true;

GridReport.PageSize = 10;

GridReport.MasterTableView.AllowCustomPaging =

true;

GridReport.AutoGenerateColumns =

false;

GridReport.AllowFilteringByColumn =

false;

GridReport.EnableLinqExpressions =

false;

GridReport.GridLines =

GridLines.None;

GridReport.NeedDataSource +=

new GridNeedDataSourceEventHandler(this.GridReport_NeedDataSource);

GridReport.PageIndexChanged +=

new GridPageChangedEventHandler(this.GridReport_PageIndexChanged);

GridReport.PagerStyle.Mode =

GridPagerMode.NextPrevNumericAndAdvanced;

GridReport.ClientSettings.Scrolling.AllowScroll =

true;

GridReport.ClientSettings.Scrolling.UseStaticHeaders =

true;

GridReport.ClientSettings.Resizing.AllowColumnResize =

true;

GridReport.ClientSettings.Resizing.EnableRealTimeResize =

true;

GridReport.MasterTableView.AllowSorting =

true;

GridReport.MasterTableView.AllowNaturalSort =

false;

GridReport.MasterTableView.HierarchyLoadMode =

GridChildLoadMode.ServerOnDemand;

GridReport.ClientSettings.AllowExpandCollapse =

true;

GridReport.MasterTableView.TableLayout =

GridTableLayout.Fixed;

GridReport.MasterTableView.Width =

Unit.Pixel(1413);

GridReport.FilterMenu.EnableAjaxSkinRendering =

true;

GridReport.ClientSettings.AllowColumnsReorder =

false;

GridReport.ClientSettings.AllowDragToGroup =

false;

GridReport.ClientSettings.ReorderColumnsOnClient =

true;

GridReport.ClientSettings.Resizing.ResizeGridOnColumnResize =

true;

GridReport.ClientSettings.Resizing.ClipCellContentOnResize =

true;

GridReport.ClientSettings.EnableRowHoverStyle =

true;

GridReport.ClientSettings.ClientEvents.OnRowSelected =

"RowSelected";

GridReport.ClientSettings.Selecting.AllowRowSelect =

true;

 

 

LoadReport(GridReport);

GridPlaceHolder.Controls.Add(GridReport);

}


private void LoadReport(RadGrid GridReport)

{

 

 

    string reportName = "Report_Operations";

    switch (reportName )

     {

    case "Report_Operations":

     GridReport.MasterTableView.DataKeyNames =

    new string[] { "OperationID" };

     GridReport = BLL.BO.Reports.

    Operations.GenerateReportColumns(ref GridReport);

    break;
}

 

 

 

private void GridReport_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

{
    //do something

    GridReport.DataSource = dt;}

 

 

void GridReport_PageIndexChanged(object source, GridPageChangedEventArgs e)

 {

            // DO SOMETHING, HERE THE BREAKPOINT NEVER HITS!
}

Thanks for your help!

6 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 May 2012, 12:09 PM
Hello,

Please check below forum. (in this forum also Similar issue)
http://www.telerik.com/community/forums/aspnet-ajax/grid/access-dynamic-grid-column-and-rows.aspx

Note : your condition should be
if (!string.IsNullOrEmpty(Request.Params["__EVENTTARGET"]))
        {
            if (Request.Params["__EVENTTARGET"].ToString() == "btnGenerate" || Request.Params["__EVENTTARGET"].ToString() == "GridReport")
            {
                creategrid();
            }
        }



Thanks,
Jayesh Goyani
0
Covertix
Top achievements
Rank 1
answered on 17 May 2012, 02:03 PM
Thank you very much Jayesh.
Your response was really helpful.

I solved the issue with the PageIndexChanged event, but PageSizeChanged event still doesn't fire.
Do you have any idea why?

Thanks.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 May 2012, 06:31 AM
Hello,

Please check after pagging changes are able to fired item_command event or not?
Note :  also  set enableviewstate is true.


Thanks,
Jayesh Goyani
0
Covertix
Top achievements
Rank 1
answered on 20 May 2012, 08:48 AM
Hi Jayesh,

I don't use item_command event.
I use enableviewstate = false, because I got an exception when I changed it to true.

I can make the page_changed event to be fired, but e.NewPageSize still has the previous value (before the change)The same happens for me when I change page index using the numeric textbox (and not the buttons).
The event is fired, but e.NewPageIndex has the previuos value.
0
Daniel
Telerik team
answered on 24 May 2012, 09:42 AM
Hi Tzach,

I would recommend that you create your control on Page_Init. This is the most bulletproof approach in my opinion. See the attached demo.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Covertix
Top achievements
Rank 1
answered on 28 May 2012, 07:51 AM
Hi Daniel,

That's what I did.
I solved the problem, and now the events get fired.

The problem now is, that inside the event GridReport_PageSizeChanged, when I try to get the new value (e.NewPageSize), the value still contains the old one (before the change).
For example, If the initial value is 10, and I change to 20, e.NewPageSize returns 10.
The same happens when the event GridReport_PageIndexChanged is fired when I change the page size from textbox and not from the buttons. (I get the old value).
Do you have any idea why?

Thanks!
Tags
Grid
Asked by
Covertix
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Covertix
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or