Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
2.25/5 (4 votes)
See more:
how to select gridview row using link button in template field
Posted

1 solution

Hi,
Here is an example:

XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TableSeq"
            DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%# Eval("TableSeq") %>'
                            CommandName="Select" Text="Select" oncommand="LinkButton1_Command"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="TableSeq" HeaderText="TableSeq" ReadOnly="True" SortExpression="TableSeq" />
                <asp:BoundField DataField="Text" HeaderText="Text" SortExpression="Text" />
            </Columns>
            <SelectedRowStyle BackColor="#FF6666" />
        </asp:GridView>



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.

Cheers.
 
Share this answer
 
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900