我在datagird里通过代码增加了一按钮列,可是我确捕获不到它的单击事件?
我在datagird里通过代码增加了一按钮列,可是我确捕获不到它的单击事件?
ButtonColumn bc = new ButtonColumn();
bc.ButtonType = ButtonColumnType.PushButton;
bc.CommandName = "btnSendAgain ";
bc.HeaderText = "重发 ";
bc.Text = "发送 ";
WorkWithDataGrid1.Columns.Add(bc);
//我用这个代码捕获不到上面增加按钮的事件
private void WorkWithDataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if ( e.CommandName == "btnSendAgain ")
{
lblErrorViewer.Text = TransactionId.ToString();
}
if ( e.CommandName == "Select ")
{
lblErrorViewer.Text = "Select ";
}
}
//通过属性生成器增加的
<asp:ButtonColumn Text= "选择 " CommandName= "Select "> </asp:ButtonColumn>
btnSendAgain这个按钮通过程序增加的捕获不到,Select这个按钮在界面中通过datagrid的属生生成器自动增加的确可以捕获到。这是为什么?
------解决方案-------------------- if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType=ListItemType.AlternatingItem)
{
if ( e.CommandName == "btnSendAgain ")
{
lblErrorViewer.Text = TransactionId.ToString();
}
if ( e.CommandName == "Select ")
{
lblErrorViewer.Text = "Select ";
}
}