Click here to Skip to main content
14,383,854 members
Rate this:
Please Sign up or sign in to vote.
See more:
how to select gridview row using link button in template field

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Here is an example:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TableSeq"

            DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                <asp:TemplateField ShowHeader="False">
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%# Eval("TableSeq") %>'

                            CommandName="Select" Text="Select" oncommand="LinkButton1_Command"></asp:LinkButton>
                <asp:BoundField DataField="TableSeq" HeaderText="TableSeq" ReadOnly="True" SortExpression="TableSeq" />
                <asp:BoundField DataField="Text" HeaderText="Text" SortExpression="Text" />
            <SelectedRowStyle BackColor="#FF6666" />

In this code, LinkButton1_Command will fire first and then GridView1_SelectedIndexChanged will fire. You can use e.CommandArgument, e.CommandName in the LinkButton1_Command.

Gopal Rakhal 8-Apr-12 4:54am
Thanks I have solved.........
Reza Ahmadi 8-Apr-12 5:23am
Thank you for your vote! What was the reason for that vote? My solution does not work or it is not related to your problem? Which one?
Gopal Rakhal 8-Apr-12 21:30pm
Ohhh I just got hint from u and solved it!!!!!!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100