在DataGrid中模版列中放一个按钮,可以响应itemcommand事件,如果现在有两个按钮,怎么区分,我单击的是哪一个呢

解决方案 »

  1.   

    <asp:button commandname="button1" ID="button1" runat="server" /> //第一个按钮
    <asp:button commandname="button2" ID="button2" runat="server" /> //第二个按钮事件
    itemcommand中:
    if(e.commandname=="button1") //单击第一个按钮的事件
    {
    //.....
    }
    if(e.commandname=="button2") //单击第二个按钮的事件
    {
    //.....
    }
    以上为手写,有书写错误自己纠正
      

  2.   

    根据按钮的CommandNameprivate void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
    {
    if(e.CommandName == "XXX")
    {
    //
    }
    else(e.CommandName == "YYY")
    {
    //
    }
    }