Nishant.Chauhan80 Ответов: 1

Как получить идентификатор linkbutton из gridview в событии pageindexchanging


how to get linkbutton id from gridview in pageindexchanging event


Что я уже пробовал:

how to get linkbutton id from gridview in pageindexchanging event

1 Ответов

Рейтинг:
1

ITGeekCoder

Define the button in your grid view markup and assign a CommandName value to the button, like this


<pre><asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server"  

        OnRowCommand="GridView1_RowCommand">
    <Columns>
        <asp:TemplateField HeaderText="Add Record">
            <ItemTemplate>
                <asp:Button ID="btnAddRecord"  

                            CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" 

                            CommandName="AddRecord" runat="server" Text="Add" />
            </ItemTemplate>
        </asp:TemplateField> 
    </Columns>
</asp:GridView>


Now in your code-behind, you can handle the OnRowCommand event and AddRecord command, like this:


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "AddRecord")
    {
        // Get index of row passed as command argument
        int index = Convert.ToInt32(e.CommandArgument.ToString());

        // Your logic here
    }
}