Print this page
Tuesday, 15 January 2013 16:24

how to show Gridview items details using DetailsView

Written by 
Rate this item
(0 votes)

GridView is the most common data representation
contol in's needed to show users the
items details when the item is selected.DetailsView
control can be used precisely to show the Gridview items

following codes show how to use DetailsView control with GridView
control to
show details -

in the aspx page -

<asp:GridView ID="studentGridView" runat="server" AutoGenerateColumns="False"
AutoGenerateSelectButton="True" DataKeyNames="Id"
<asp:BoundField DataField="Id" HeaderText="Student Id" />
<asp:BoundField DataField="Name" HeaderText="Student Name" />
<br />
<br />
<asp:DetailsView ID="studentDetailsView" runat="server"
AutoGenerateRows="False" Height="50px" Width="125px">
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Address" HeaderText="Address" />

use code behind file to populate GridView from database,
then include the following codes to show details for each
item using detailsview -

protected void studentGridView_SelectedIndexChanged(object sender, EventArgs e)
int id = Convert.ToInt16(studentGridView.SelectedValue);
//get details on id from database
students = studentGateway.GetStudent(id);
studentDetailsView.DataSource = students;

Read 2789 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments