要达到效果:点击  ImageButton2 删除每一行数据  前台:<asp:GridView ID="GridView1" runat="server" Height="309px" Width="498px"     
                      HorizontalAlign="Center"  AutoGenerateColumns="False" CellPadding="0" 
                      GridLines ="None" AllowPaging="True"  > 
         <PagerSettings Visible="False" />
          
         <Columns>
                                               
                 
              <asp:BoundField HeaderText="起始时间" DataField="起始时间"  DataFormatString="{0:yyyy-MM-dd}" >
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                     <ControlStyle Width="60px"></ControlStyle>
                    <ItemStyle HorizontalAlign="Center" />
               </asp:BoundField>
                             
           
   <asp:TemplateField   >
                               
       <ItemTemplate  >
         <asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/memo.gif" />
         <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/gai.gif" />
         <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/del.gif" CommandName="Del"  CommandArgument='<%# Eval("ID") %>' />
                                                          
       </ItemTemplate>
                                 
                     <HeaderStyle Width="70px" HorizontalAlign="Center" VerticalAlign="Bottom" />
                    <ItemStyle HorizontalAlign="Center" />
                 </asp:TemplateField>
                                
      </Columns>
                        
                                
</asp:GridView>后台:
   protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       
       if (e.CommandName == "Del")
       {
           int i = Convert.ToInt32(e.CommandArgument);
           string strTitle = GridView1.Rows[i].Cells[1].Text;
           Response.Write(strTitle);
       } 
        
   }点击:ImageButton2 没反应?

解决方案 »

  1.   

    commandName 名称问题
    换个名称就行
    你用DEL 是关键字,他不会走 ROwCommand事件
    走的是Deleting事件
      

  2.   

    try:
    Response.Write(i.ToString());
      

  3.   

    嗯,试一下把commandname名称换一个
      

  4.   

    if (e.CommandName == "Del")
    好像连这个位置都没运行到
      

  5.   

    先把名字给改了。再设置调试啊。如果不行。try catch一下咯。看看哪里出错了!
      

  6.   

        <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/del.gif" CommandName="De"  CommandArgument='<%# Eval("ID") %>' />
                                      
     protected  void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           
           if (e.CommandName == "De")
           {
              // int i = Convert.ToInt32(e.CommandArgument);
              // string strTitle = GridView1.Rows[i].Cells[1].Text;
               Response.Write("hello");
           } 
            
       }
      

  7.   

    <asp:GridView ID="GridView1" runat="server" Height="309px" Width="498px"   
      HorizontalAlign="Center" AutoGenerateColumns="False" CellPadding="0"  
      GridLines ="None" AllowPaging="True" 
    onrowcommand="GridView1_RowCommand" >