Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / Web Data Grid ItemCommand Not Firing

Web Data Grid ItemCommand Not Firing

New Discussion
DJ Roedger
DJ Roedger asked on Sep 14, 2016 5:12 PM

Since the version 14.1.20141.2283 upgrade, clicking a link button inside a Template Item does not fire the ItemCommand  method when a webdatagrid is set to EnableDataViewState=”true”. If I set EnableDataViewState=”false” and rebind the grid each postback the ItemCommand method fires as expected. This behavior was not occurring in the previous version of 14.1. Is this a known error? How can I fix it with rebinding my grids on each postback?

Sign In to post a reply

Replies

  • 0
    Jason D.
    Jason D. answered on Nov 5, 2014 5:57 PM

    Hello droedger,

    The reason that the ItemCommand event is failing to fire is that templates of the grid are instantiated in the DataBind method of the grid. Normally if this method is not manually called it gets called during the OnPreRender event for the grid. However, when using this with the ItemCommand the DataBind event is fired after the ItemCommand event is supposed to fire. Since the templates haven't been instantiated in time the event can't find the templates and fails out silently.

    The way to resolve this issue is to ensure that the templates exist. You can do this by adding the following code to your PageLoad event:

    if (IsPostBack) {

       WebDataGrid1.EnsureTemplates();
    }

    The way that it was working previously in the older versions was not actually the intended behavior of the control. This new approach is the correct way to implement ItemCommands, TemplateColumns, and EnableDataViewState. Please let me know if you have any questions or concerns about this approach, or let me know if I may be of any other help.

    • 0
      Johnie Bristow
      Johnie Bristow answered on Nov 14, 2014 9:25 PM

      Thank you!!!! I just spent 3 hours trying to track down why this stopped working properly in 14.2. Numerous Google searches through me off track and I tried numerous "tricks" to no avail. This simple line…added to my existing code…fixed everything. 

      • 0
        Prasad Talla
        Prasad Talla answered on Dec 10, 2015 11:32 AM

        Hello I am working with Google Chrome, Infragistics version 15.2 the event is not firing. Could you please help us on this issue.

        Thanks

        Prasad Talla

      • 0
        Jason D.
        Jason D. answered on Dec 10, 2015 2:01 PM

        Hello Prasad,

        Did you call EnsureTemplates as I suggested in this thread? If this is not working then it would be recommended that you create a support case with more details about what you have done and how your grid has been set up so that we can look in to this issue further.

      • 0
        Prasad Talla
        Prasad Talla answered on Dec 10, 2015 2:05 PM

        Hello the above solution is working for IE11 but not working for Google Chrome.

        Ok I will create a case on this.

        Regards

        Prasad Talla

  • 0
    Nguyen Huu Tung
    Nguyen Huu Tung answered on Sep 12, 2016 10:05 AM

    Hello Jason D, I call EnsureTemplates as you suggested in this thread. But It only working in the first post back. I do not understand what is happening,

    You can help me?

    Thank you!

    • 0
      Michael Peterson
      Michael Peterson answered on Sep 12, 2016 5:12 PM

      Hello Nguyen,

      I have tested this in our latest service release for v16.1 which is 2044 and it is working for me. What version are you using, including the service release? Do you have a sample that demonstrates the behavior you are seeing?

      • 0
        Nguyen Huu Tung
        Nguyen Huu Tung answered on Sep 13, 2016 2:54 AM

        Hello Mike,

        I'm using v15.5 and I set EnableViewState = true; EnableDataViewState = true in WebdatagridInit.

        In PageLoad I also added code

        if (IsPostBack) {

           WebDataGrid1.EnsureTemplates();
        }

        But when webdatagrid change the datasource then ItemCommand not working.

      • 0
        Michael Peterson
        Michael Peterson answered on Sep 13, 2016 9:38 PM

        Hello Nguyen,

        I have tested this with both the latest version of v15.1 (2400) and v15.2 (2195) and I have been unable to reproduce the issue you describe. Please attach a sample demonstrating the behavior you are seeing.

      • 0
        Nguyen Huu Tung
        Nguyen Huu Tung answered on Sep 14, 2016 4:14 AM

        Hello Mike,

        In WebDataGrid I set

        protected void WebDataGrid1_Init(object sender, EventArgs e)
        {
        WebDataGrid grid = sender as WebDataGrid;

        //列の自動作成をしない
        grid.AutoGenerateColumns = false;
        grid.DataKeyFields = "社員CD";
        grid.EnableViewState = true;
        grid.EnableDataViewState = true;
        //grid.EnableAjaxViewState = true;
        //grid.EnableAjax = false;
        //grid.ClientEvents.Click = "WebDataGrid1_Click";
        //grid.ClientEvents.AJAXResponse = "AJAXResponse";
        grid.ClientEvents.KeyDown = "WebDataGrid1_Grid_KeyDown";
        grid.RowUpdating += new Infragistics.Web.UI.GridControls.RowUpdatingHandler(WebDataGrid1_RowUpdating);
        grid.InitializeRow += this.WebDataGrid1_InitializeRow;
        grid.ItemCommand += this.WebDataGrid1_ItemCommand;
        grid.ActiveCellChanged += this.WebDataGrid1_ActiveCellChanged;

        // コントロール レベルで Ajax インジケーターを有効にします
        grid.AjaxIndicator.Enabled = Infragistics.Web.UI.DefaultableBoolean.True;
        // Ajax インジケーター表示時にマスクをかける。
        grid.AjaxIndicator.BlockArea = Infragistics.Web.UI.AjaxIndicatorBlockArea.Page;
        // Ajax インジケーターの位置を設定します
        grid.AjaxIndicator.Location = Infragistics.Web.UI.RelativeLocation.MiddleCenter;
        // コントロール固有の Ajax インジケーターの位置を設定します
        grid.AjaxIndicator.RelativeToControl = Infragistics.Web.UI.DefaultableBoolean.True;

        //セルのアクティブ化の有効化
        if (grid.Behaviors.Activation == null)
        {
        Activation aActivation = new Activation();
        aActivation.ActiveCellCssClass = "ActiveCellSelector";
        aActivation.ActivationClientEvents.ActiveCellChanging = "ActiveCellChanging";
        // 動作コレクションに追加します
        grid.Behaviors.Add(aActivation);
        }

        //セル編集機能の有効化
        if (grid.Behaviors.EditingCore == null)
        {
        EditingCore aEditingCore = new EditingCore();
        aEditingCore.AutoCRUD = false;
        aEditingCore.BatchUpdating = true;
        aEditingCore.Behaviors.CreateBehavior<Infragistics.Web.UI.GridControls.CellEditing>();
        aEditingCore.Behaviors.CellEditing.EditModeActions.MouseClick = Infragistics.Web.UI.GridControls.EditMouseClickAction.Single;
        aEditingCore.Behaviors.CellEditing.EditModeActions.EnableOnKeyPress = true;
        aEditingCore.EditingClientEvents.CellValueChanging = "CellValueChanging";
        aEditingCore.EditingClientEvents.CellValueChanged = "CellValueChanged";
        aEditingCore.Behaviors.CellEditing.CellEditingClientEvents.EnteringEditMode = "EnteringEditMode";
        // 動作コレクションに追加します
        grid.Behaviors.Add(aEditingCore);
        }

        //列固定化の有効化
        if (grid.Behaviors.ColumnFixing == null)
        {
        ColumnFixing ColumnFixingbehavior = new ColumnFixing();
        ColumnFixingbehavior.FixLocation = FixLocation.Left;
        ColumnFixingbehavior.AutoAdjustCells = false;
        ColumnFixingbehavior.ShowFixButtons = false;

        // 動作コレクションに追加します
        grid.Behaviors.Add(ColumnFixingbehavior);
        }

        //グリッドで選択動作を有効にします。
        if (grid.Behaviors.Selection == null)
        {
        Selection aSelection = new Selection();
        aSelection.CellClickAction = CellClickAction.Cell;
        aSelection.CellSelectType = SelectType.Multiple;

        // 動作コレクションに追加します
        grid.Behaviors.Add(aSelection);
        }
        }

        First, I set all column is BoundDataField,

        for (int i = 0; i < GridData.Instance.ColumnCount; i++)
        {
        string key = COLUMN_DEFAULT + i;
        BoundDataField gridField = new BoundDataField(true);
        gridField.Key = key;
        gridField.DataFieldName = key;
        gridField.Header.CssClass = "hidden";
        gridField.CssClass = "HorizontalAlign_Left";

        aWebDataGrid.Columns.Add(gridField);

        }

        After, I set again Template in InitializeRow.

        protected void WebDataGrid1_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
        {
        WebDataGrid grid = (WebDataGrid)sender;
        //Set Height
        if (GridData.Instance[e.Row.Index].Height > 0)
        e.Row.Height = GridData.Instance[e.Row.Index].Height;

        //Set template item
        int start = 1;
        for (int i = start; i < grid.Columns.Count; i++)
        {
        int rowIndex = e.Row.Index;
        int columnIndex = i – 1;

        if (GridData.Instance.ShowType.GetValue() == Common.Master.C_ShowType.LANDSCAPE)
        {
        rowIndex = i – 1;
        columnIndex = e.Row.Index;
        }

        CellData rCell = GridData.Instance[rowIndex, columnIndex];

        e.Row.Items[i].CssClass = rCell.ClassCss;
        //Set Backgound
        if (!string.IsNullOrEmpty(rCell.BackColor))
        e.Row.Items[i].CssClass = e.Row.Items[i].CssClass + rCell.BackColor;

        CellType cellType = rCell.CellType;
        if (cellType == CellType.BOUNDDATAFIELD)
        {
        if (rCell.Locked)
        e.Row.Items[i].Template = new LabelTemplate(e.Row.Items[i].Column.Key);
        }
        else if (cellType == CellType.COMBOBOX)
        {
        DropDownTemplate template = rCell.Template as DropDownTemplate;
        if (rCell.Locked)
        template.Locked = true;
        e.Row.Items[i].Template = template;
        }
        else if (cellType == CellType.RADIOBUTTON)
        {
        RadioButtonTemplate template = rCell.Template as RadioButtonTemplate;
        if (rCell.Locked)
        template.Locked = true;
        e.Row.Items[i].Template = template;
        }
        else if (cellType == CellType.LINKBUTTON)
        {
        LinkButtonTemplate template = rCell.Template as LinkButtonTemplate;
        if (rCell.Locked)
        template.Locked = true;
        e.Row.Items[i].Template = template;
        }
        }
        }

        Linkbutton ItemCommand still working, but when datasource grid change then ItemCommand not working.

        Please help me. Thank you!

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
DJ Roedger
Favorites
0
Replies
11
Created On
Sep 14, 2016
Last Post
9 years, 6 months ago

Suggested Discussions

Created by

Created on

Sep 14, 2016 5:12 PM

Last activity on

Feb 26, 2026 7:14 PM