Link DetailsView with SqlDataSource and do the editing : DetailsView « ADO.net Database « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » ADO.net Database » DetailsView 
Link DetailsView with SqlDataSource and do the editing


<%@ Page Language="C#"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="sourceProducts" 
                           runat="server"
                           ProviderName="System.Data.SqlClient"
                           ConnectionString="<%$ ConnectionStrings:Northwind %>"
                           SelectCommand="SELECT ProductID, ProductName, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued FROM Products"
                           UpdateCommand="UPDATE Products SET ProductName=@ProductName, UnitPrice=CONVERT(money, @UnitPrice), UnitsInStock=@UnitsInStock, UnitsOnOrder=@UnitsOnOrder, ReorderLevel=@ReorderLevel, Discontinued=@Discontinued WHERE ProductID=@ProductID"
                           DeleteCommand="DELETE Products WHERE ProductID=@ProductID"
                           InsertCommand="INSERT INTO Products (ProductName, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued) VALUES (@ProductName, CONVERT(money, @UnitPrice), @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued)">  
        </asp:SqlDataSource>
        <asp:DetailsView ID="DetailsView1" 
                         runat="server" 
                         Height="50px" 
                         Width="125px"  
                         DataKeyNames="ProductID"
                         AllowPaging="True" 
                         DataSourceID="sourceProducts"
                         AutoGenerateInsertButton="true" 
                         AutoGenerateDeleteButton="true" 
                         AutoGenerateEditButton="true">
            <PagerSettings PageButtonCount="25" />            
        </asp:DetailsView>
        <br />
    </div>
    </form>
</body>
</html>


File: Web.config


<?xml version="1.0"?>

<configuration>

  <connectionStrings>
    <add name="Northwind" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI"/>
  </connectionStrings>
</configuration>

 
Related examples in the same category
1.Using a PagerTemplate to customize the paging interface.
2.Editing a record with the DetailsView control.
3.Displaying a Master/Detail form with the DetailsView control.
4.Using a template when editing with the DetailsView control.
5.Handling Concurrency Issues: CompareAllValues or OverwriteChanges
6.Inserting Data with the DetailsView Control
7.Deleting Data with the DetailsView Control
8.Use the ItemInserted event to handle any errors
9.Adding an AutoGenerateInsertButton attribute to the DetailsView
10.Using the GridView and DetailsView together
11.Enabling paging on the DetailsView control
12.Customizing the display of the DetailsView control
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.