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

ImageButton is not triggering Item_Command Event

1 Answer 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim Holmgren
Top achievements
Rank 1
Jim Holmgren asked on 13 Nov 2008, 05:54 PM

Hi,

 

 

   I am generating the RadGrid (ASPNET AJAX Q1 2008) dynamically (Creating entire grid programmatically). Since the grid has child controls (as part of GridTemplateColumn & PagerTemplate) I had set EnableViewState = False for Grid as well as page (according to this article: http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html). But the problem is I have “ImageButton” inside GridTemplateColumn. It has CommandName property set. When I click on the ImageButton, it does not trigger “ItemCommand” event handler. But the LinkButton works perfect. So, in order to make sure I am doing right; I had created a sample project which does the similar functionality. Here is the code:

 

 

<%@ Page Language="C#" AutoEventWireup="True" EnableEventValidation="false" CodeBehind="RadGridTest.aspx.cs" Inherits="Adc.Web.AdBid.Views.CampaignView.RadGridTest" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

     <asp:ScriptManager ID="ScriptManager1" runat="server"/>

        <telerik:RadGrid ID="rad" runat="server" runat="server" EnableViewState="False"  OnNeedDataSource="RadGrid_NeedDataSource"

             OnItemCommand="RadGrid_ItemCommand" OnItemDataBound="RadGrid_ItemDataBound"   AllowPaging="true" AutoGenerateColumns="false" 

             HeaderStyle-Wrap="true"  PagerStyle-AlwaysVisible="true">            

                <MasterTableView  PagerStyle-AlwaysVisible="true" EditMode="InPlace" TableLayout="Auto" ShowFooter="True" >

                <Columns>

                <telerik:GridTemplateColumn UniqueName="CampaignName" DataField="CampaignName" HeaderText="Campaign Name">

                        <ItemTemplate>

                            <asp:LinkButton ID="testCampaignBtn" runat="server" CommandName="Campaign" Text='<%# DataBinder.Eval(Container.DataItem,"CampaignName") %>'></asp:LinkButton>

                            <asp:ImageButton ID="testCBtn" runat="server" CommandName="EditCampaign" ImageUrl="~/Images/edit_icon.gif" EnableViewState="true" />

                        </ItemTemplate>

                    </telerik:GridTemplateColumn>

                   

                    <telerik:GridBoundColumn UniqueName="Status" DataField="Status" HeaderText="Status"></telerik:GridBoundColumn>

                    <telerik:GridTemplateColumn UniqueName="EditCampaignImage">

                        <ItemTemplate>

                            <asp:ImageButton ID="testImageBtn" runat="server" CommandName="EditCampaign" ImageUrl="~/Images/edit_icon.gif" EnableViewState="true" />

                        </ItemTemplate>

                    </telerik:GridTemplateColumn>

                </Columns>

                <RowIndicatorColumn Visible="False">

                    <HeaderStyle Width="20px" />

                </RowIndicatorColumn>

                <ExpandCollapseColumn Visible="False" Resizable="False">

                    <HeaderStyle Width="20px" />

                </ExpandCollapseColumn>

                <EditFormSettings>

                    <PopUpSettings ScrollBars="None" />

                </EditFormSettings>

                </MasterTableView>

        </telerik:RadGrid>

    </form>

</body>

</html>

 

 

Code Behind:

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Globalization;

 

using Telerik.Web.UI;

 

using Adc.SelfService.Patterns;

using Adc.SelfService.Configuration;

using Adc.SelfService.AdBid;

using Adc.Data.AdBid;

using Adc.Web.AdBid.Common;

using Adc.Web.UI.Controls;

using Adc.Services.Adbid;

using Adc.SelfService;

 

namespace Adc.Web.AdBid.Views.CampaignView

{

    public partial class RadGridTest : System.Web.UI.Page

    {

        Guid OrderId = new Guid("3bfd9791-daba-4e62-bb42-c02ba465992f");

        protected void Page_Load(object sender, EventArgs e)

        {

           

        }

        protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

        {

            LoadCampaignData();

 

        }

        protected void RadGrid_ItemCommand(object sender, GridCommandEventArgs e)

        {

             switch(e.CommandName)

            {

                case "EditCampaign":

                    string str = "Do Something";

                    str = str + "...";

                    break;

                 case "Campaign":

                    string str1 = "Do Campaign";

                    str1 = str1 + "...";

                    break;

             }

        }

        protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)

        {

        }

        private void LoadCampaignData()

        {

            if (OrderId != null && OrderId != Guid.Empty)

            {

                object[] param = new object[4];

                param[0] = OrderId;

                param[1] = null;// (string.IsNullOrEmpty(campaignSummaryView.SortFieldName)) ? "" : campaignSummaryView.SortFieldName;

                param[2] = null;// campaignSummaryView.SortOder;

                param[3] = Adc.Data.AdBid.CampaignStatus.All;

                CampaignPresenter p = new CampaignPresenter();

                CampaignDataMiner miner = new CampaignDataMiner();

                ISelfServiceViewData data = miner.GetData(param);

                CampaignCollection cc = ((Adc.Data.AdBid.Campaign)data).CampaignSummaryCollection; ;

                rad.DataSource = cc;

                rad.VirtualItemCount =  miner.GetVirtualItemCount(param);

            }

        }

     }

}

 

  Note that it’s a sample project for your reference. In actual project I am generating the grid programatically. Please provide the solution to this at the earliest. Some one can please help me with a better solution.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Nov 2008, 06:07 AM
Hi Jim,

I tried this on my end and it is working well with EnableViewState set to true but i get an error when it is set to false. Try to achieve the same with EnableViewState set to true. I am not sure whether there exists any alternative to achieve this with EnableViewState set to false.

Here is the code I tried.

ASPX:
<telerik:GridTemplateColumn UniqueName="TempCol1"    DataField="ProductName" SortExpression="ProductName"  HeaderText="TempCol1"   > 
      <ItemTemplate> 
          <asp:ImageButton ID="ImageButton1" runat="server"  CommandName="ImageCheck"/> 
      </ItemTemplate> 
    </telerik:GridTemplateColumn> 


CS:
 protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        if (e.CommandName == "ImageCheck") 
        { 
            
        } 
    } 


Thanks
Shinu.
Tags
Grid
Asked by
Jim Holmgren
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or