What doesn't an ItemTemplate child control fire an ItemCommand??

Discussion in 'ASP .Net Datagrid Control' started by Mark Sisson, Dec 17, 2003.

  1. Mark Sisson

    Mark Sisson Guest

    Could someone explain to me why my first column in my datagrid below
    doesn't fire the event while the second column does??? I don't
    understand why controls within an item template that have a
    CommandName don't go anywhere. What's the point?? Do you have to use
    ButtonColumns to fire events???

    TIA

    ===========RELAVENT ASPX CODE============
    <asp:DataGrid id="grdMain"AutoGenerateColumns="False"
    DataKeyField="orderid">
    <Columns>
    <asp:BoundColumn DataField="orderid"
    HeaderText="orderid"></asp:BoundColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:ImageButton id="ImageButton1" runat="server"
    CommandName="Select" ImageUrl="images/edit.gif"></asp:ImageButton>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:ButtonColumn runat='server' Text='<img border=0
    src="images/edit.gif">' CommandName=Select>
    </asp:ButtonColumn>
    </Columns>
    </asp:DataGrid>


    ===========ASPX CODEBEHIND ============
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace LandmarkIntranetPortal
    {
    /// <summary>
    /// Summary description for Test.
    /// </summary>
    public class Test : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid grdMain;

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection con = new
    SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand cmd = new SqlCommand("select * from [order]",con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    grdMain.DataSource = ds;
    grdMain.DataBind();
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web
    //Form Designer.
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.grdMain.ItemCommand += new
    System.Web.UI.WebControls.DataGridCommandEventHandler(this.grdMain_ItemCommand);
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void grdMain_ItemCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    Debug.Write("here!!!");
    }
    }
    }
     
    Mark Sisson, Dec 17, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan
    Replies:
    2
    Views:
    11,453
    Shawn Mehaffie
    Jan 22, 2004
  2. Jeremy
    Replies:
    0
    Views:
    405
    Jeremy
    Jul 2, 2004
  3. Bennett Haselton
    Replies:
    1
    Views:
    5,407
    Joe Fallon
    Sep 24, 2004
  4. Jeff Rodriguez
    Replies:
    23
    Views:
    1,200
    David Schwartz
    Dec 9, 2003
  5. Sal
    Replies:
    2
    Views:
    177
Loading...

Share This Page