How to fire Direct event on the dynamic CommandColumn?

  1. #1

    How to fire Direct event on the dynamic CommandColumn?

    Good Morning!
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    <%@ Import Namespace="ListView=Ext.Net.ListView"%>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Convert.ToString(1);
                Store store = new Store { ID = "StoreRow_" + id };
                Model model = new Model();
    
                DataTable dtTrend = new DataTable();
                dtTrend.Columns.Add("Name", typeof(string));
                dtTrend.Columns.Add("Data", typeof(int));
                dtTrend.Rows.Add("Day 1 ", 0);
                dtTrend.Rows.Add("Day 2 ", 0);
                dtTrend.Rows.Add("Day 3 ", 0);
                dtTrend.Rows.Add("Day 4 ", 0);
                dtTrend.Rows.Add("Day 5", 0);
                dtTrend.Rows.Add("Day 6", 0);
    
                foreach (DataColumn dc in dtTrend.Columns)
                {
                    ModelField modelField = new ModelField { Name = dc.ColumnName, Mapping = dc.ColumnName, Type = ModelFieldType.String };
                    model.Fields.Add(modelField);
                }
                store.Model.Add(model);
    
                store.DataSource = dtTrend;
                GrdSessions.Store.Add(store);
                foreach (DataColumn dc in dtTrend.Columns)
                {
                    GrdSessions.ColumnModel.Columns.Add(new Column { Text = dc.ColumnName.Replace('_', ' '), DataIndex = dc.ColumnName, Width = 100 });
                } 
    
                CommandColumn commandColumn = new CommandColumn();
                commandColumn.ID = "colAction" + System.Guid.NewGuid();
                commandColumn.Flex = 1;
                commandColumn.Text = "View";
                commandColumn.DataIndex = "Id";
                commandColumn.Commands.Add(new GridCommand { Icon = Ext.Net.Icon.Note, CommandName = "View", Text = "View" });           
                commandColumn.DirectEvents.Command.Event += GrdInbox_Command;
                commandColumn.DirectEvents.Command.ExtraParams.Add(new Parameter { Name = "Id", Value = "record.data.Id" });
                commandColumn.DirectEvents.Command.ExtraParams.Add(new Parameter { Name = "command", Value = "command" });
                GrdSessions.ColumnModel.Columns.Add(commandColumn);
                GrdSessions.Render(pnlSessionGeneric, 0, RenderMode.InsertTo);
            }
    
            protected void GrdInbox_Command(object sender, DirectEventArgs e)
            {
                string commandName = e.ExtraParams["command"];
                long Id = Convert.ToInt64(e.ExtraParams["Id"]);
            }
    
    </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 id="Form1" runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Panel ID="pnlSessionGeneric" runat="server" AutoScroll="true" Border="false"
            autowidth="true" Layout="FitLayout" Header="false" Height="230">
            <Content>
                <ext:GridPanel ID="GrdSessions" runat="server" Layout="AnchorLayout" AnchorHorizontal="100%"
                    Padding="5" Title="Session List" AnimCollapse="true" AutoScroll="true" Height="200">
                    <ColumnModel ID="ColumnModel1" runat="server">
                        <Columns>
                        </Columns>
                    </ColumnModel>
                    <View>
                        <ext:GridView ID="GridView1" runat="server" TrackOver="true" />
                    </View>
                </ext:GridPanel>
            </Content>
        </ext:Panel>
        </form>
    </body>
    </html>
    when i click on view button then is show error. "the control with Id colAction00000#0000 not found."
    can you help me where and what i am missing
  2. #2
    Hello!

    It would be best to post in the Help forums:

    http://forums.ext.net/forumdisplay.php?18-2-x-Help


    http://forums.ext.net/forumdisplay.php?4-1-x-Help


    About your question: You have to use the same IDs for each controls which taking a part in DirectEvent or throw DirectEvent:

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            
                string id = Convert.ToString(1);
                Store store = new Store {ID = "StoreRow_" + id};
                Model model = new Model();
    
                DataTable dtTrend = new DataTable();
                dtTrend.Columns.Add("Name", typeof(string));
                dtTrend.Columns.Add("Data", typeof(int));
                dtTrend.Rows.Add("Day 1 ", 0);
                dtTrend.Rows.Add("Day 2 ", 0);
                dtTrend.Rows.Add("Day 3 ", 0);
                dtTrend.Rows.Add("Day 4 ", 0);
                dtTrend.Rows.Add("Day 5", 0);
                dtTrend.Rows.Add("Day 6", 0);
    
                foreach (DataColumn dc in dtTrend.Columns)
                {
                    ModelField modelField = new ModelField
                                                {Name = dc.ColumnName, Mapping = dc.ColumnName, Type = ModelFieldType.String};
                    model.Fields.Add(modelField);
                }
                store.Model.Add(model);
    
                store.DataSource = dtTrend;
                GrdSessions.Store.Add(store);
                foreach (DataColumn dc in dtTrend.Columns)
                {
                    GrdSessions.ColumnModel.Columns.Add(new Column
                                                            {
                                                                Text = dc.ColumnName.Replace('_', ' '),
                                                                DataIndex = dc.ColumnName,
                                                                Width = 100,
                                                                ID = dc.ColumnName
                                                            });
                }
    
                CommandColumn commandColumn = new CommandColumn();
                commandColumn.ID = "colAction";
                commandColumn.Flex = 1;
                commandColumn.Text = "View";
                commandColumn.DataIndex = "Id";
                commandColumn.Commands.Add(new GridCommand {Icon = Ext.Net.Icon.Note, CommandName = "View", Text = "View"});
                commandColumn.DirectEvents.Command.Event += GrdInbox_Command;
                commandColumn.DirectEvents.Command.ExtraParams.Add(new Ext.Net.Parameter {Name = "Id", Value = "record.data.Id", Mode = ParameterMode.Raw});
                commandColumn.DirectEvents.Command.ExtraParams.Add(new Ext.Net.Parameter {Name = "command", Value = "command"});
                GrdSessions.ColumnModel.Columns.Add(commandColumn);
                GrdSessions.Render(pnlSessionGeneric, 0, RenderMode.InsertTo);
        }
    
        protected void GrdInbox_Command(object sender, DirectEventArgs e)
            {
                string commandName = e.ExtraParams["command"];
                string name = e.ExtraParams["Name"];
            }
     
    </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 id="Form1" runat="server">
        <ext:ResourceManager runat="server" SourceFormatting="True" ScriptMode="Debug" />
        <ext:Panel ID="pnlSessionGeneric" runat="server" AutoScroll="true" Border="false"
            autowidth="true" Layout="FitLayout" Header="false" Height="230">
            <Content>
                <ext:GridPanel ID="GrdSessions" runat="server" Layout="AnchorLayout" AnchorHorizontal="100%"
                    Padding="5" Title="Session List" AnimCollapse="true" AutoScroll="true" Height="200">
                    <ColumnModel ID="ColumnModel1" runat="server">
                        <Columns>
                        </Columns>
                    </ColumnModel>
                    <View>
                        <ext:GridView ID="GridView1" runat="server" TrackOver="true" />
                    </View>
                </ext:GridPanel>
            </Content>
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; Nov 08, 2012 at 2:48 AM.

Similar Threads

  1. [CLOSED] Dynamic header column component direct event Issue
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 21, 2015, 10:56 PM
  2. Replies: 8
    Last Post: Sep 10, 2012, 6:38 AM
  3. Replies: 5
    Last Post: Jun 25, 2012, 6:19 PM
  4. SortChange Direct Event doesn't fire at all
    By cicaglisa in forum 1.x Help
    Replies: 1
    Last Post: May 23, 2012, 5:31 PM
  5. [CLOSED] adding direct event to CommandColumn
    By Sevilay Tanış in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 23, 2012, 2:37 PM

Posting Permissions