In this article we will introduce with DetailsView control in ASP.NET using C#.
DetailsView Example in ASP.NET using C#
DetailsView control in ASP.NET is used to display single record at a time. You can insert, edit, delete and paging the record in DetailsView. In this example we use SQLDataSource for providing data. You can AutoFormat the DetailsView. You can see the following image for AutoFormat.
You will click on special tag button and checks true enable paging. You can see the following figure.
DetailsView.aspx (Design Page):
DetailsView.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="DetailsView.aspx.cs" Inherits="DetailsView" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> DetailsView in ASP.NET 4, C#</h2> <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="326px" AllowPaging="True" AutoGenerateRows="False" CellPadding="4" DataSourceID="SqlDataSource1" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" /> <EditRowStyle BackColor="#999999" /> <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" /> <Fields> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" /> <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" /> <asp:BoundField DataField="Course" HeaderText="Course" SortExpression="Course" /> <asp:BoundField DataField="Branch" HeaderText="Branch" SortExpression="Branch" /> <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> <asp:BoundField DataField="MobileNo" HeaderText="MobileNo" SortExpression="MobileNo" /> </Fields> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderTemplate> Student Information </HeaderTemplate> <PagerStyle BackColor="#284775" Font-Names="Verdana" Font-Size="Small" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource> </div> </asp:Content>
[ 0 ] Comments