我给一个GridView绑定了数据
a   b  c    按钮
a1  b1 c1   按钮1 
a2  b2 c2   按钮2
.........
按钮那一列是模板列,请问如何点击按钮调用aspx.cs 中的一个方法??????????

解决方案 »

  1.   

    <asp:ButtonField ButtonType="Button" CommandName="DownLoad" Text="取得" >protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                try
                {
                    if (e.CommandName == "DownLoad")
                    {
                           ....
                    }
            }
      

  2.   

     protected void gvwClass_RowCommand(object sender,  GridViewCommandEventArgs e)
        {
            index = Convert.ToInt32(e.CommandArgument);
             //fundction();
        }
      

  3.   

    这样行吗`?
    是根据数据循环就越多按妞。。不可能都CommandName 吧`
    哈哈
    我也遇到这样的问题
      

  4.   

    int row = Convert.ToInt32(e.CommandArgument);  //row  就是行号
                        string FilePath = GridView1.DataKeys[row].Value.ToString();
      

  5.   

    beckhans 
    贝克汉鸭说得很清楚了.
      

  6.   

    程序报错
      e.CommandArgument的值为null
      

  7.   

    你要传ID,就把 button的CommandArgument属性帮定上ID
      

  8.   

    不可能阿,e.CommandArgument是CLR负值,把你的source贴出来看看
      

  9.   

    protected void gvwClass_RowCommand(object sender,  GridViewCommandEventArgs e)
        {
            index = Convert.ToInt32(e.CommandArgument);
            //fundction();
        }
    在这样取就可以
      

  10.   

    “/WebSite4”应用程序中的服务器错误。
    --------------------------------------------------------------------------------输入字符串的格式不正确。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.FormatException: 输入字符串的格式不正确。源错误: 
    行 23:         if (e.CommandName == "aaa")
    行 24:         {
    行 25:             int row = Convert.ToInt32(e.CommandArgument);  //row  就是行号
    行 26:            TextBox1.Text = GridView1.DataKeys[row].Value.ToString();
    行 27:         }
     源文件: e:\WebSite3\WebSite4\Default.aspx.cs    行: 25 堆栈跟踪: 
    [FormatException: 输入字符串的格式不正确。]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2752915
       System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102
       System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43
       System.Convert.ToInt32(Object value) +25
       _Default.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in e:\WebSite3\WebSite4\Default.aspx.cs:25
       System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +96
       System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +121
       System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +163
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
       System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +119
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +107
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +178
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3837 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42 
      

  11.   

     <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="aaa" Text="按钮" />C#
     protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "aaa")
            {
                int row = Convert.ToInt32(e.CommandArgument);  //row  就是行号
               //TextBox1.Text = GridView1.DataKeys[row].Value.ToString();
            }
        }
      

  12.   

    e.CommandArgument   等于 null 吧,
    <asp:Button ID="Button1" runat="server" CommandArgument='<%# Bind("ID") %>' Text="Button" CommandName="Up" />
      

  13.   


    这样行吗`? 
    是根据数据循环就越多按妞。。不可能都CommandName 吧` 
    哈哈 
    我也遇到这样的问题 
      

  14.   

    大哥,你不是说Button是GridView的魔板列吗,那应该是
    <asp:ButtonField ButtonType="Button" CommandName="DownLoad" Text="取得" >而你的是
    <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="aaa" Text="按钮" /> 分明你的是一个普通的按钮阿