SIGN UP MEMBER LOGIN:    
ARTICLE

DetailsView in Asp.net

Posted by Dinkar Chavhan Articles | ASP.NET Programming April 15, 2011
The DetailsView control in ASP.Net 2.0 is used to create an HTML table that displays the contents of a single database record.
Reader Level:
Download Files:
 

The DetailsView control in ASP.Net 2.0 is used to create an HTML table that displays the contents of a single database record.

Step 1:

  • Open Visual Studio
  • Add a webForm to your website, name it DetailsView.aspx
  • Add a DataSource control to the page and configure it to a database

Step 2: If you want to have paging in DetailsView like a Gridview then go to the Smart tag of the DetailsView and select Enable paging.

See code below:

<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
        AutoGenerateRows="False" CellPadding="4" DataSourceID="SqlDataSource1"
        ForeColor="#333333" GridLines="None" Height="50px" Width="125px">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <RowStyle BackColor="#EFF3FB" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <Fields>
            <asp:BoundField DataField="Username" HeaderText="Username"
                SortExpression="Username" />
            <asp:BoundField DataField="Password" HeaderText="Password"
                SortExpression="Password" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="Address" HeaderText="Address"
                SortExpression="Address" />
        </Fields>
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:DetailsView>

This is the ConnectionString, which is automatically generated when we select a data source:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:telecomConnectionString %>"
        SelectCommand="SELECT [Username], [Password], [Email], [Address] FROM [User_Registration]">
    </asp:SqlDataSource>

DetailsView Fields in ASP.Net

You can control the appearance of the DetailsView.

asp.net.gif

Step 3: Now run the application and verify that it works.
 

Login to add your contents and source code to this article
share this article :
post comment
 

nice one

Posted by Ankit Nandekar Apr 15, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor