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


Mark Sisson

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???


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

===========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
SqlCommand cmd = new SqlCommand("select * from [order]",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
grdMain.DataSource = ds;

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

/// <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
this.Load += new System.EventHandler(this.Page_Load);


private void grdMain_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question