Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<asp:GridView ID="grdtopic" runat="server" AutoGenerateColumns="false" CssClass="grdtopic" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" OnRowCommand="grdtopic_RowCommand" Width="200px" OnSelectedIndexChanged="grdtopic_SelectedIndexChanged">
<alternatingrowstyle backcolor="#DCDCDC">
<footerstyle backcolor="#CCCCCC" forecolor="Black">
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="#999999" forecolor="Black" horizontalalign="Center">
<rowstyle backcolor="#EEEEEE" forecolor="Black">
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F1F1F1">
<sortedascendingheaderstyle backcolor="#0000A9">
<sorteddescendingcellstyle backcolor="#CAC9C9">
<sorteddescendingheaderstyle backcolor="#000065">

<columns><asp:TemplateField HeaderText="ID">
<itemtemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Eval("TopicID") %>'>


<asp:TemplateField HeaderText="Topic">
<itemtemplate>
<asp:LinkButton ID="lblTopic" OnClick="Senddata_Click" CommandName="Select" CommandArgument='<%# Eval("TopicID") %>' runat="server"><%# Eval("Topic Name") %> Paper


how to selected row in GridView on LinkButton Click event or SelectedIndexChanged?
plz help sir ....
that gridview selectedvalue display on label .....
plz plz plz help me...........
Posted

you can do as below
C#
protected void grdtopic_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Select")
    {
        LinkButton lnk = (LinkButton)e.CommandSource;
        string TopicID = lnk.CommandArgument;
        // do something
    }
}
 
Share this answer
 
v2
Comments
iamvinod34 17-Dec-14 10:59am    
sir how to display selected row on label?
DamithSL 17-Dec-14 11:01am    
where is your label? if it is outside of gridview try like below
label1.Text = TopicID ;
Refer - GridView.RowCommand Event[^].

Put the index as the CommandArgument as shown in the second example. Also see how you can get the GridViewRow inside the Event.
 
Share this answer
 

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