[CLOSED] How to call CellSelect event from codebehind

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] How to call CellSelect event from codebehind

    Hi All,

    I created the GridPanel from codebehind and now I tried to call the event "CellSelect" in the same way but
    I receive at the run time the error "object expected"

    The my source code is :

    CellSelectionModel cellSelectionModel = new CellSelectionModel();
                cellSelectionModel.Listeners.CellSelect.Handler = "Cellclick()";
                gridPanelReportBacklog.SelectionModel.Add(cellSelectionModel);
    
            protected void Cellclick(object sender, DirectEventArgs e) {
                CellSelectionModel sm = (CellSelectionModel) this.gridPanelReportBacklog.SelectionModel.Primary;
                string phase = gridPanelReportBacklog.ColumnModel.Columns[sm.SelectedCell.ColIndex].Header;
                     }
    Error details: URI: http://localhost/trp/(S(a4ebwi55o5i2fi55drwcgo55))
    /extjs/ext-all-js/ext.axd?v=37522


    Can you help me for this issue?
    I hope was clear.
    Thanks
    Last edited by Daniil; Feb 27, 2012 at 8:57 AM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi,

    Please clarify what moment does the error occur and when do you create a GridPanel - during initial page load or during DirectEvent?

    Also, please clarify are you expecting to call "Cellclick" DirectEvent handler this way?
    cellSelectionModel.Listeners.CellSelect.Handler = "Cellclick()";
    The DirectEvent handler should be attached this way:
    cellSelectionModel.DirectEvents.CellSelect.Event += Cellclick;
  3. #3
    Hi,

    I create the gridPanel during the DirectEvent of button.
    I agree with you on change my code as you suggest

    cellSelectionModel.DirectEvents.CellSelect.Event += Cellclick;
    but I receive the NullReferenceException. Run time error when I click on the GridPanel cell

    Click image for larger version. 

Name:	Cattura1.JPG 
Views:	50 
Size:	93.5 KB 
ID:	3833

    Thank you so much for your support.
    Last edited by Daniil; Feb 20, 2012 at 5:53 PM. Reason: Please use [CODE] tags
  4. #4
  5. #5
    Hi,

    Now it works,
    the event run correctly when I click on the GridPanel cell but the row index and column index is not inizialized. I receive out of range exception because
    sm.SelectedCell.ColIndex = -1
    My Page_Load

    CellSelectionModel cellSelectionModel = new CellSelectionModel();
                cellSelectionModel.ID = "cellSelectionModelBacklog";
                cellSelectionModel.DirectEvents.CellSelect.Event += new ComponentDirectEvent.DirectEventHandler(CellSelected);
                gridPanelReportBacklog.SelectionModel.Add(cellSelectionModel);
                gridPanelReportBacklog.Hidden = true;
                panelReportBacklog.Items.Add(gridPanelReportBacklog);
    Method CellSelected

     protected void CellSelected(object sender, DirectEventArgs e) {
                CellSelectionModel sm = (CellSelectionModel) this.gridPanelReportBacklog.SelectionModel.Primary;
                string phase = gridPanelReportBacklog.ColumnModel.Columns[sm.SelectedCell.ColIndex].Header;
            }
    Thanks
    Last edited by Daniil; Feb 20, 2012 at 5:53 PM. Reason: Please use [CODE] tags
  6. #6
    Please create a CellSelectionModel within Page_Init instead of Page_Load.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Init(object sender, EventArgs e)
        {
            CellSelectionModel sm = new CellSelectionModel();
            sm.DirectEvents.CellSelect.Event += OnCellSelect;
            this.GridPanel1.SelectionModel.Add(sm);
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test1", "test2", "test3" },
                    new object[] { "test4", "test5", "test6" },
                    new object[] { "test7", "test8", "test9" },
                };
                store.DataBind();
            }
        }
    
        protected void OnCellSelect(object sender, DirectEventArgs e)
        {
            var sm = sender as CellSelectionModel;
            X.Msg.Alert("OnCellSelect", sm.SelectedCell.RowIndex + " : " + sm.SelectedCell.ColIndex).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="test1" />
                                    <ext:RecordField Name="test2" />
                                    <ext:RecordField Name="test3" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="Test1" DataIndex="test1" />
                        <ext:Column Header="Test2" DataIndex="test2" />
                        <ext:Column Header="Test3" DataIndex="test3" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
  7. #7
    I move the code as you suggest but I receive the same error
    Careful because the my GridPanel created from code behind
            private void Page_Init(object sender, System.EventArgs e) {
                this.defaultScreenView = new ViewDefaultScreen();
                this.gridPanelReportBacklog = new GridPanel();
                this.InitViewFields();
                
                CellSelectionModel cellSelectionModel = new CellSelectionModel();
                cellSelectionModel.ID = "cellSelectionModelBacklog";
                cellSelectionModel.DirectEvents.CellSelect.Event += CellSelected;
                gridPanelReportBacklog.SelectionModel.Add(cellSelectionModel);
            }
    Thank you so much
    Last edited by Daniil; Feb 21, 2012 at 4:37 AM. Reason: Please use [CODE] tags
  8. #8
    Please provide a full sample to reproduce the problem, like the example I have posted.
  9. #9
    The problem was that my GridPanel was in another panel but I forget to call the panel.Render()

    Thanks
  10. #10
    Please clarify can we mark the thread as closed?
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: Apr 09, 2013, 4:03 PM
  2. Replies: 2
    Last Post: Jul 20, 2012, 7:26 PM
  3. [CLOSED] How to Call an event by Direct Events
    By Oliver in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 12, 2012, 6:33 PM
  4. Problem with javascript and cellselect
    By bolzi89 in forum 1.x Help
    Replies: 2
    Last Post: Jan 10, 2012, 2:21 PM
  5. [CLOSED] DirectEvents call method codebehind
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Sep 05, 2011, 3:03 PM

Posting Permissions