使用服务器端控件,然后在datagrid里有oncommand事件的.

解决方案 »

  1.   

    <input type="image".......>,

    <asp:image有对应的事件
      

  2.   

    应该放置一个imageButton,并使用其commandName属性
    <asp:ImageButton id="ImageButton1" runat="server"  CommandName="image_click"></asp:ImageButton>然后,在datagrid的ItemCommand事件中加入代码(假设key是string)private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    if(e.CommandName=="image_click")
    {
      string currentKey = (string)DataList1.DataKeys[e.Item.ItemIndex]));
    }
    }
      

  3.   

    将<input type="image".......>改为服务器端的ImageButton控件,将其CommandArgument属性设为“mycmd”
    在datagrid的ItemCommand事件绑定的函数里,如:private void MyDataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
       if(e.CommandName == "mycmd")
       {
            …… '你的过程
        }
    }
      

  4.   

    你只能把事件写在DataGrid的ItemCommand事件中才能触发,获得DataKeyField你可以加以绑定列,设置为隐藏,需要的时候去绑定列的内容不就可以了么
    比如:绑定列为第一列:
    private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        Response.Write("<script>alert('"+e.Item.Cells[1].Text+"');</script>");

    }
      

  5.   

    是不是所有摸板列里的控件的事件都只能用 ITEMCOMMAND 来引发 ??
      

  6.   

    我试过了 不行啊  不执行事件 在 <asp:datagrid ... onitemcommand="mygrid_itemcommand"...>代码中这样写的 : 
       sub mygrid_itemcommand(sender As Object, e As DataGridCommandEventArgs)
         if e.commandname="img1_click" then
    Dim  mygrid3  As  DataGrid  
             mygrid3  = CType(e.Item.FindControl("mygrid2"),  DataGrid) 
    dim itemcell as tablecell=e.item.cells(2)
    dim d_id=itemcell.text
    response.write(d_id)
    sql="select * from [Office] where D_ID='"& d_id &"'"
    response.write(sql)
    myadapter=new sqldataadapter(sql,myconn)
    myconn.open()
    myadapter.fill(mydataset,"office")
    mygrid3.datasource=mydataset.tables("office")
    mygrid3.databind()
    myconn.close()
       end if
     end sub 
      

  7.   

    在你的mygrid控件事件属性itemcommand 栏,检查是否指定到了你的事件mygrid_itemcommand
    要是没有,则在itemcommand 栏双击鼠标左键。会执行你的事件的。
      

  8.   

    是的:)
    应该在 "属性"-"事件" 里面的 ItemCommand 事件栏 双击激活itemCommand事件,这样会自动生成该事件的委托代码,然后在生成的函数里面写就可以了