You can select a row of ASP.Net GridView Data Control using postback event of button control or link button control by passing the Command="select". Command property of button or link button control passes the name of command i.e. action to be taken on the clicked row item. When user clicks on any row item of GridView it sends the row index along with command specified for the button control. You can use the GridView TemplateField to display the data items retrieved from the SQL Database table. GridView provides the autoGenerateSelectButton property that accepts true or false. If autoGenerateSelectButton property is set tot true then GridView Control automatically renders the select button at runtime to select the row item. You can also use the GridView CommandField column to handle the GridView Select command. When you specify a command as select for CommandField or autoGenerateSelectButton="true" GridView control automatically handles the event to change the selected Row Index.
In this tutorial for GridView Control Select Row, we have used the Northwind SQL database and GridView is bound with category table.
<style type="text/css">
font-family:arial;
}
text-decoration:none;
.gridHeader th {
</style>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None" Width="400px"
SelectedRowStyle-BackColor="#e1e1e1" CellPadding="4" CssClass="gridHeader">
<Columns>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<asp:CommandField HeaderText="Select" ShowHeader="True" ShowSelectButton="True" >
</asp:CommandField>
</Columns>
</asp:GridView>
Output:
Currently rated 5.0 by 1 people
Tags: asp.net 2.0, asp.net gridview, asp.net gridview select, asp.net gridview select command, asp.net gridview commandfield, asp.net gridview datasource, asp.net gridview paging, asp.net gridview sorting
10/11/2008 3:40:32 AM