如何GridView  中添加事件 如何GridView  中加入一个buttonfield   如何使他具有onclick 事件并获得选中行一列的值!!!帮帮忙谢谢

解决方案 »

  1.   

    <asp:Button ID="Button3" runat="server" CommandName="Insert" CommandArgument='<%#Eval("id") %>' Text="添加" />gridView__RowCommand事件
    GridViewRow row = ((Control)e.CommandSource).BindingContainer as GridViewRow;
      if (e.CommandName == "Insert")
      {
      int id = int.Parse(e.CommandArgument.ToString());
      string str = ((TextBox)row.FindControl("TextBox3")).Text;
      

  2.   

    click事件
    Button btn=sender as Button();
    GridViewRow gvr = (sender as Button).NamingContainer as GridViewRow;   
    TextBox txt=gvr.FindControl("txt") as TextBox;
      

  3.   


    把指定ButtionFile的CommandName属性值,然后转换成模板列就可以传参数了模板列页面代码:
      <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                CommandArgument='<%# Eval("teacherId", "{0}") %>' CommandName="aaa" Text="按钮"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>然后再GridView的RowCommand获取当前按钮的参数就可以了
       protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName=="aaa")
            {
                string str = e.CommandArgument.ToString();
            }
        }
    不过最好用LinkBotton按钮,或者图片按钮,弄个图片样式就可了,这样方便传递参数 ,GridViw的几个事件作用不一样哟,