How to get selected row values in gridview

The sample code is below try it:

Use the below code html page.

<asp:GridView runat="server" ID="grdprj"AutoGenerateColumns="false"



<asp:BoundField HeaderText="Projcet Name" DataField="ProjectName" />

<asp:ButtonField ButtonType="Link" CommandName="Select" Text="Select" />



Use the below code in code behind page:

protected void grdprj_RowCommand(object sender, GridViewCommandEventArgs e)


// If multiple buttons are used in a GridView control, use the

// CommandName property to determine which button was clicked.

if (e.CommandName == "Select")


// Convert the row index stored in the CommandArgument

// property to an Integer.

int index_page = Convert.ToInt32(e.CommandArgument);

// Retrieve the row that contains the button clicked

// by the user from the Rows collection.

GridViewRow grdrow = grdprj.Rows[index_page];



About the Author