M
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???
TIA
===========RELAVENT ASPX CODE============
<aspataGrid 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>
</aspataGrid>
===========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!!!");
}
}
}
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============
<aspataGrid 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>
</aspataGrid>
===========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!!!");
}
}
}