A
Andrea Williams
I still consider myself to be a novice with ASP.NET, and going through the
samples in my books is not helping me spot the problem. I very often find
my answer after I've posted so maybe it will happen again?
I'm having trouble getting an ButtonColumn click event to fire. I set a
break point in the event method and it doesn't break.
here's my Datagrid in the ASPX file:
<asp:datagrid id="dgdSearchResults" runat="server"
OnItemCommand="dgdSearchResults_ItemCommand">
<HeaderStyle CssClass="Title"></HeaderStyle>
</asp:datagrid>
In my code-behind I have this:
protected void dgdSearchResults_ItemCommand(object sender,
DataGridCommandEventArgs e)
{
string strFunctionName = "dgdSearchResults_ItemCommand";
long lngAuthorID = 0;
CISTable.User oUser;
if (e.CommandName == "Select")
{
//An author was selected to be added to the Author hidden element
this.hidAuthorID.Value = e.Item.ItemIndex;
}
}
At design time I add a ButtonColumn to the Datagrid before I bind my
DataSet:
btn.ButtonType = ButtonColumnType.PushButton;
btn.HeaderText = "Select";
btn.CommandName = "Select";
btn.DataTextField = "AuthorID"
btn.Text = "Select";
this.dgdSearchResults.Columns.Add(btn);
btn = null;
That didn't work so I added this to the InitializeComponent() method:
this.dgdSearchResults.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdSearchResults_
ItemCommand);
Still no luck. All the other buttons, not in a Datagrid are firing the
_click events and running the methods properly, but thie button in the grid
will not. Everything appears correctly in the web browser, but when the
Button is clicked, the dgdSearchResults_ItemCommand is never entered and the
code is not executed. It only goes through Page_Load and not through the
events method.
Can anybody tell me what I'm missing before I go insane???
Andrea
PS: I ran a few searches in the KB articles, but found nothing that would
help.
samples in my books is not helping me spot the problem. I very often find
my answer after I've posted so maybe it will happen again?

I'm having trouble getting an ButtonColumn click event to fire. I set a
break point in the event method and it doesn't break.
here's my Datagrid in the ASPX file:
<asp:datagrid id="dgdSearchResults" runat="server"
OnItemCommand="dgdSearchResults_ItemCommand">
<HeaderStyle CssClass="Title"></HeaderStyle>
</asp:datagrid>
In my code-behind I have this:
protected void dgdSearchResults_ItemCommand(object sender,
DataGridCommandEventArgs e)
{
string strFunctionName = "dgdSearchResults_ItemCommand";
long lngAuthorID = 0;
CISTable.User oUser;
if (e.CommandName == "Select")
{
//An author was selected to be added to the Author hidden element
this.hidAuthorID.Value = e.Item.ItemIndex;
}
}
At design time I add a ButtonColumn to the Datagrid before I bind my
DataSet:
btn.ButtonType = ButtonColumnType.PushButton;
btn.HeaderText = "Select";
btn.CommandName = "Select";
btn.DataTextField = "AuthorID"
btn.Text = "Select";
this.dgdSearchResults.Columns.Add(btn);
btn = null;
That didn't work so I added this to the InitializeComponent() method:
this.dgdSearchResults.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdSearchResults_
ItemCommand);
Still no luck. All the other buttons, not in a Datagrid are firing the
_click events and running the methods properly, but thie button in the grid
will not. Everything appears correctly in the web browser, but when the
Button is clicked, the dgdSearchResults_ItemCommand is never entered and the
code is not executed. It only goes through Page_Load and not through the
events method.
Can anybody tell me what I'm missing before I go insane???
Andrea
PS: I ran a few searches in the KB articles, but found nothing that would
help.