gridview中放一列按纽,按纽点击事件怎么知道获取的哪一行呢?

解决方案 »

  1.   

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        e.RowIndex//获得事件的行的index
    }<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="Button1" CommandName="Update" runat="server" Text="Button" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
      

  2.   

    注意点:1.按钮CommandName="Update" 就是借用RowUpdating这个事件(其实方法中可以完全不写任何有关更新的操作)
    2.得到了index的值 可以通过int index = e.RowIndex;
    Button btn = (Button)GridView1.Rows[index].FindControl("Button1");来获得控件。
    当然得到了index的值 什么都好商量了。