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

Grid Itemcommand Event not fire When used ImageButton

5 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhavesh
Top achievements
Rank 1
Bhavesh asked on 14 Dec 2009, 06:20 AM
Hello,
        When i am using <telerik:GridButtonColumn ButtonType="ImageButton" Text="Select" CommandName="select" ImageUrl="~/App_Themes/WebBlue/Grid/images/Hand.png" CommandArgument="Select" >
in gridview instead of button then gridview command event not fired
        So describe why this event not fired when used Imagebutton instead of PushButton and how to overcome this problem.
        Reply me as soon  as possible


Regards,
Bhavesh Rana

5 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 16 Dec 2009, 12:16 PM
Hi Bhavesh,

I tried to replicate the issue which you described, but to no avail. Attached to this message, you will find the code which I used for testing. Take a look at it and let me know if there are any differences at your end, which I may be leaving out.

Greetings,

Mira
the Telerik team

 


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Guillaume
Top achievements
Rank 1
answered on 17 Dec 2009, 10:42 AM
I have the same problem.

If I use a LinkButton, the event is fired, if i use an ImageButton, nothing happens.
0
Mira
Telerik team
answered on 19 Dec 2009, 02:37 PM
Hello Guillaume,

Have you examined the sample project attached in my previous message?

Please take a look at it and if the problems persist, provide more details about your scenario so that we can assist you further.

Kind regards,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
obuliprakash
Top achievements
Rank 1
answered on 14 Mar 2014, 03:54 PM
Hi Mira,

I am creating a radgrid with child grid dynamically in code.
main grid has a template column with buttons which on click will open the detailTables.
Till this it is working fine. but in child grid am creating a template column with some text boxes and buttons.
On click of button in this i am expecting ItemCommandEvent which i never receive.

Please let me know if am missing some information or is it wrong.#
I have attached the sample application i have created.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
 
namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        private DataStruct myStructure;
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            myStructure = CreateData();
            DefineGrid();
        }
 
        private DataStruct CreateData()
        {
            IList<int> aIntList = new List<int>() {1,2,3,4,5};
            IList<string> aStringList = new List<string>(){"a","b","c","d","e"};
            DataStruct aStruct = new DataStruct(aIntList,aStringList);
            return aStruct;
        }
 
        private void DefineGrid()
        {
            DummyGrid.MasterTableView.EnableViewState = false;
            DummyGrid.MasterTableView.Name = "MainGrid";
            DummyGrid.MasterTableView.EnableColumnsViewState = false;
            DummyGrid.MasterTableView.DataKeyNames = new[] {"Number"};
            DummyGrid.AutoGenerateColumns = false;
            DummyGrid.ClientSettings.Scrolling.AllowScroll = true;
            DummyGrid.ClientSettings.Scrolling.UseStaticHeaders = true;
            DummyGrid.ClientSettings.Selecting.AllowRowSelect = false;
            DummyGrid.NeedDataSource += new GridNeedDataSourceEventHandler(WorkflowGrid_NeedDataSource);
            DummyGrid.ItemCommand += new GridCommandEventHandler(WorkflowGrid_ItemCommand);
            DummyGrid.PreRender += new EventHandler(WorkflowGrid_PreRender);
            DummyGrid.ItemDataBound += new GridItemEventHandler(WorkflowGrid_ItemDataBound);
            DummyGrid.DetailTableDataBind += new GridDetailTableDataBindEventHandler(WorkflowGrid_DetailTableDataBind);
 
            GridBoundColumn aNumberColumn = new GridBoundColumn { HeaderText = "Number" };
            DummyGrid.MasterTableView.Columns.Add(aNumberColumn);
            aNumberColumn.UniqueName = "Number";
            aNumberColumn.DataField = "Number";
            aNumberColumn.Visible = false;
 
            GridBoundColumn aDataColumn = new GridBoundColumn { HeaderText = "Data" };
            DummyGrid.MasterTableView.Columns.Add(aDataColumn);
            aDataColumn.UniqueName = "Data";
            aDataColumn.DataField = "Data";
            aDataColumn.Visible = true;
 
            GridTemplateColumn aActionsTemplateCol = new GridTemplateColumn();
            DummyGrid.MasterTableView.Columns.Add(aActionsTemplateCol);
            aActionsTemplateCol.ItemTemplate = new ButtonsTemplate("Actions");
            aActionsTemplateCol.UniqueName = "Actions";
            aActionsTemplateCol.Visible = true;
            aActionsTemplateCol.HeaderText = "Actions";
            aActionsTemplateCol.HeaderTooltip = "Actions";
            aActionsTemplateCol.DataField = "Actions";
 
            GridTableView aChildGrid = new GridTableView();
            DummyGrid.MasterTableView.DetailTables.Add(aChildGrid);
            aChildGrid.Name = "Details";
 
            GridBoundColumn aWorkFlowIdCol = new GridBoundColumn();
            aChildGrid.Columns.Add(aWorkFlowIdCol);
            aWorkFlowIdCol.UniqueName = "String";
            aWorkFlowIdCol.HeaderText = "String";
            aWorkFlowIdCol.DataField = "String";
            aWorkFlowIdCol.Visible = true;
 
 
            GridTemplateColumn aTemplateColumn = new GridTemplateColumn();
            aChildGrid.Columns.Add(aTemplateColumn);
            aTemplateColumn.ItemTemplate = new ButtonsTemplate("ChildActions");
            aTemplateColumn.UniqueName = "EditTabs";
            aTemplateColumn.DataField = "EditTabs";
            aTemplateColumn.Visible = true;
        }
 
        protected void WorkflowGrid_NeedDataSource(object sender_in, GridNeedDataSourceEventArgs args_in)
        {
            if (myStructure != null)
            {
                DataTable aMainTable = new DataTable();
                aMainTable.Columns.Add("Number"typeof (int));
                aMainTable.Columns.Add("Data"typeof (int));
                aMainTable.Columns.Add("Actions"typeof (ITemplate));
                IList<int> aList = myStructure.IntList;
                foreach (int i in aList)
                {
                    DataRow aDataRow = aMainTable.NewRow();
                    aDataRow["Number"] = i;
                    aDataRow["Data"] = i;
                    ButtonsTemplate aButtonTemplate = new ButtonsTemplate("Actions_" + i);
                    aDataRow["Actions"] = aButtonTemplate;
                    aMainTable.Rows.Add(aDataRow);
                }
                DummyGrid.DataSource = aMainTable;
            }
        }
 
        protected void WorkflowGrid_ItemCommand(object sender_in, GridCommandEventArgs args_in)
        {
            string aText = args_in.CommandName;
            GridDataItem aDataItem = (GridDataItem)args_in.Item;
            if (aText == "CopyCmd")
            {
                if (aDataItem.OwnerTableView.Name == "Details")
                {
                    
                }
                else if (aDataItem.OwnerTableView.Name == "MainGrid")
                {
                    aDataItem.ChildItem.Visible = true;
                    aDataItem.Expanded = true;
                }
            }
        }
 
        protected void WorkflowGrid_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
            GridDataItem aDataItem = (GridDataItem) e.DetailTableView.ParentItem;
            DataTable aEditTabTable = new DataTable();
            aEditTabTable.Columns.Add("string"typeof (string));
            aEditTabTable.Columns.Add("EditTabs"typeof (ITemplate));
 
            int aNumber = (int)aDataItem.GetDataKeyValue("Number");
            ButtonsTemplate aEditNamesTab = new ButtonsTemplate("Actions");
            DataRow aEditDataRow = aEditTabTable.NewRow();
 
            aEditDataRow["String"] = myStructure.StringList[aNumber];
            aEditDataRow["EditTabs"] = aEditNamesTab;
            aEditTabTable.Rows.Add(aEditDataRow);
 
 
            e.DetailTableView.DataSource = aEditTabTable;
        }
 
        protected void WorkflowGrid_PreRender(object sender_in, EventArgs args_in)
        {
            DummyGrid.MasterTableView.ExpandCollapseColumn.Visible = false;
        }
 
        protected void WorkflowGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
 
            }
        }
    }
 
    public class ButtonsTemplate : ITemplateIDisposable
    {
        private Button myCopyButton;
        private Button myEditButton;
        private string myColName;
 
        public ButtonsTemplate(string columnName_in)
        {
            myColName = columnName_in;
        }
 
        public void InstantiateIn(Control container)
        {
            myCopyButton = new Button();
            myCopyButton.ID = "Copy" + container.ClientID;
            myCopyButton.Text = "Copy";
            myCopyButton.CommandName = "CopyCmd";
 
            myEditButton = new Button();
            myEditButton.ID = "Edit" + container.ClientID;
            myEditButton.Text = "Edit";
            myEditButton.CommandName = "EditCmd";
 
            container.Controls.Add(myCopyButton);
            container.Controls.Add(myEditButton);
        }
 
        public void Dispose()
        {
            if (myCopyButton != null)
            {
                myCopyButton.Dispose();
            }
            if (myEditButton != null)
            {
                myEditButton.Dispose();
            }
        }
    }
    public class DataStruct
    {
        private IList<int> myIntList;
        private IList<string> myStringList; 
        public DataStruct(IList<int> intList, IList<string> stringList)
        {
            myIntList = intList;
            myStringList = stringList;
        }
 
        public IList<int> IntList
        {
            get { return myIntList; }
            set { myIntList = value; }
        }
 
        public IList<string> StringList
        {
            get { return myStringList; }
            set { myStringList = value; }
        }
    }
}
0
Princy
Top achievements
Rank 2
answered on 17 Mar 2014, 07:05 AM
Hi,

When creating TemplateColumns you have to enable the ViewState. Please check this article on Creating a RadGrid Programmatically to know more about this.

C#:
DummyGrid.MasterTableView.EnableViewState = true;

Thanks,
Princy
Tags
Grid
Asked by
Bhavesh
Top achievements
Rank 1
Answers by
Mira
Telerik team
Guillaume
Top achievements
Rank 1
obuliprakash
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or