<HTML>
<body>
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"
                     AutoGenerateColumns="False"  
                     OnItemCommand=DataGrid1_ItemCommand>
<HeaderStyle ForeColor="Black" 
                         BackColor="Green"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="ID" ReadOnly="True" 
                           HeaderText="Status"></asp:BoundColumn>
<asp:BoundColumn DataField="StudentName" 
                            ReadOnly="True" 
                            HeaderText="Status"></asp:BoundColumn>
<asp:BoundColumn DataField="Score" ReadOnly="True" 
                            HeaderText="Status"></asp:BoundColumn>
<asp:TemplateColumn><ItemTemplate >
<asp:ImageButton Runat="server" id="btnApprove" 
                          ImageUrl="/pwcclaiming/Images/Warning.JPG" 
                           CommandName="DataGrid1_ItemCommand"
CommandArgument="10">
                           </asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn> 
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
'这是简单的一个datagrid定义Public Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As  
        System.Web.UI.WebControls.DataGridCommandEventArgs) Handles   
        DataGrid1.ItemCommand
        response.write("hello")
End Sub就这么简单, 居然响应不到imagebutton的click,接近崩溃边缘

解决方案 »

  1.   

    lz 的代码里的CommandName="命令名"
    这个名字应该是Update   Delete之类的名称
    而lz 那里写是是事件DataGrid1_ItemCommand
    这样肯定是不对的!~
    所以你单击就不会响应了!
      

  2.   

    应该是在DataGrid的事件里双击ItemCommand事件,然后在后台代码里写上:
    if(CommandName=="命令名")
    {
    执行的操作
    }
      

  3.   

    楼上的,如果没有指定命令名的话, ItemCommand 也是会被触发的呀.
    应该是事件和方法的绑定有问题, 删除这个事件,重新建一下看看CommandName="DataGrid1_ItemCommand" 这样设定倒是很有意思
      

  4.   

    <asp:TemplateColumn> <ItemTemplate > 
    <asp:ImageButton Runat="server" id="btnApprove"  
                              ImageUrl="/pwcclaiming/Images/Warning.JPG"  
                               CommandName="show" 
    CommandArgument="10"> 
                                </asp:ImageButton> 
    </ItemTemplate> protected void GvPunish_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToString().ToLower() == "show")
            {
                Response.Write(OpenCaseInfo(e.CommandArgument.ToString()));
            }
        }应该是类似的写法
      

  5.   

    朋友们,CommandName="CommandName="DataGrid1_ItemCommand"这句是我无可奈何下加进去的. 有无都无法触发Item_command事件, 是1.1版本, 如何是好?
      

  6.   

    估计是你事件的委托掉了。你多半是把Grid移动,或是页面加东西时,cut 了Grid,然后又贴上的吧
    看你Grid->events 里面的OnItemCommand 还有没有
    把事件重新加一下.