<asp:ButtonField CommandName="Upload" ButtonType="Button" Text="上传" />
<asp:ButtonField CommandName="Delete" ButtonType="Button" Text="删除" />
点击这两个按扭的触发事件是哪个?怎么写请高手帮忙,就这么多分了!全给了

解决方案 »

  1.   

    例子:
    前台:
    <asp:TemplateField HeaderText="操作">
                            <ItemTemplate>
                                <asp:Button ID="Button_Pass" runat="server" Text="通过" CommandName="Pass" CommandArgument="<%# GridView_Monitor.Rows.Count %>"
                                    OnClientClick="return confirm('确定通过吗?');" Width="96px" />
                                <asp:Button ID="Button_Cancel" runat="server" Text="扣留" CommandName="NoPass" CommandArgument="<%# GridView_Monitor.Rows.Count %>"
                                    OnClientClick="return confirm('确定扣留吗?');" Width="96px" />
                            </ItemTemplate>
                        </asp:TemplateField>
    后台.cs
                //**************得到序号
                Int32 index = Convert.ToInt32(e.CommandArgument);
                //**************得到MonitorID
                Int32 MonitorId = Convert.ToInt32(this.GridView_Monitor.Rows[index].Cells[1].Text.ToString());
                //***************操作
                if (OperDataBase.OnMonitorPassCancel(MonitorId, OperInfo.LoginOperNo, e.CommandName.ToString(), CheckIsRevert()) > 0)
                {
                    //********************记录操作日志
                    WriteLog.SaveDBOperLog(OperInfo.LoginOperNo, "MonitorID:" + MonitorId.ToString());
                    //***********************                MMsJs.CommonJs.JsAlertMsgAndRefresh(this.Page, "操作成功!");
                }
                else
                {
                    MMsJs.CommonJs.JsAlertMsg(this.Page, "操作失败!");
                }
      

  2.   

    private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    if(e.CommandName=="Upload")
    {
                                         你写的上传代码
                                }
                                if(e.CommandName=="Delete")
    {
                                         你写的删除代码
                                }
                       }
      

  3.   

    看了半天就楼上的靠点谱!可是您用的是datagrid啊!俺的是gridview啊,大同小意,请问我怎么获取当前行的rowsindex啊
      

  4.   

    在 button 中 CommandArgument 綁定對應的rowsindex,表的主鍵,然後再在rowcommand事件里寫
      

  5.   

    <%@ Page language="C#" %><script runat="server">  void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
      
        // If multiple ButtonField column fields are used, use the
        // CommandName property to determine which button was clicked.
        if(e.CommandName=="Select")
        {
        
          // Convert the row index stored in the CommandArgument
          // property to an Integer.
          int index = Convert.ToInt32(e.CommandArgument);    
        
          // Get the last name of the selected author from the appropriate
          // cell in the GridView control.
          GridViewRow selectedRow = CustomersGridView.Rows[index];
          TableCell contactName = selectedRow.Cells[1];
          string contact = contactName.Text;  
        
          // Display the selected author.
          Message.Text = "You selected " + contact + ".";
          
        }
        
      }
        
    </script><html>
      <body>
        <form runat="server">
            
          <h3>ButtonField Example</h3>
          
          <asp:label id="Message"
            forecolor="Red"
            runat="server"/>
                        
          <!-- Populate the Columns collection declaratively. -->
          <asp:gridview id="CustomersGridView" 
            datasourceid="CustomersSqlDataSource" 
            autogeneratecolumns="false"
            onrowcommand="CustomersGridView_RowCommand"
            runat="server">
                    
            <columns>
                    
              <asp:buttonfield buttontype="Button" 
                commandname="Select"
                headertext="Select Customer" 
                text="Select"/>
              <asp:boundfield datafield="CompanyName" 
                headertext="Company Name"/>
              <asp:boundfield datafield="ContactName" 
                headertext="Contact Name"/>
                    
            </columns>
                    
          </asp:gridview>
                
            <!-- This example uses Microsoft SQL Server and connects -->
            <!-- to the Northwind sample database.                   -->
            <asp:sqldatasource id="CustomersSqlDataSource"  
              selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
              connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
              runat="server">
            </asp:sqldatasource>
                
        </form>
      </body>
    </html>
      

  6.   

    在Grid的RowCommand事件中绑定onclick的事件,Button设置ComandName的属性,具体代码如:        if (e.CommandName == "view")
            {
                if (!Page.ClientScript.IsStartupScriptRegistered("OpenWindow"))
                {
                    string url = "../ApplicatForm.aspx?LangVer=" + CountryCode + "&JobCode=" + e.CommandArgument.ToString();
                    StringBuilder txtScript = new StringBuilder();
                    txtScript.Append("<script language='javascript'>\n");                txtScript.Append("window.open('" + url + "');\n");
                    txtScript.Append("</script>");
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", txtScript.ToString());
                }        }