ADD Select button in Gridview control in ASP.Net

ADD Select button in Gridview control in ASP.Net

STEP – 1 Gridview control provide system select button, just go to the Gridview property and set AutogenerateSelectButton property True.

ADD Select button in Gridview control in ASP.Net

ADD Select button in Gridview control in ASP.Net

STEP – 2  Now fire the SelectedIndexChanged Event for Select button on Gridview control.

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}

ADD Select button in Gridview control in ASP.Net

ADD Select button in Gridview control in ASP.Net

STEP -  3 Now go to the SelectedIndexchanged Event for handling coding for Select Button.

If we want to get the Value of selected row when push the select button.
we have to write our coding in selectedindexchanged event.

Suppose, we want to get the name of the selected row.
We first assign name column to Gridview control Datakeyname property.

<asp:GridView ID=”GridView1″ DataKeyNames=”name” runat=”server” Height=”216px” Width=”280px” AutoGenerateColumns=”False” AutoGenerateSelectButton=”True” OnSelectedIndexChanged=”GridView1_SelectedIndexChanged”>

<Columns>
<asp:BoundField HeaderText=”Name” DataField=”name” />
<asp:BoundField HeaderText=”Surname” DataField=”surname” />
<asp:BoundField HeaderText=”Address” DataField=”Address” />
</Columns>

</asp:GridView>

Now go to the selectedindexchanged event of Gridview control and write code for getting name of selected row.

ADD Select button in Gridview control in ASP.Net

ADD Select button in Gridview control in ASP.Net

 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
  Label1.Text = GridView1.SelectedDataKey.Value.ToString();
}

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 2 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">