Use of ListView (List View) in ASP. NET to bind source code to the foreground

Source: Internet
Author: User

1. A. Run

 

1. B, source code
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "DropLvw. aspx. cs" Inherits = "DropLvw" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Select a category: <asp: DropDownList ID = "drop" runat = "server" AutoPostBack = "True"
DataSourceID = "SqlDataSource1" DataTextField = "CategoryName"
DataValueField = "CategoryID">
</Asp: DropDownList>
<Asp: SqlDataSource ID = "SqlDataSource1" runat = "server"
ConnectionString = "<% $ ConnectionStrings: NorthwindConnectionString %>"
SelectCommand = "SELECT [CategoryID], [CategoryName] FROM [Categories]">
</Asp: SqlDataSource>
<Hr/>
Products under this category: <br/>
<Asp: ListView ID = "lvw" runat = "server" DataKeyNames = "ProductID"
Performanceid = "sqlperformance2">
<ItemTemplate>
<Tr style = "">
<Td>
<Asp: Label ID = "ProductIDLabel" runat = "server" Text = '<% # Eval ("ProductID") %>'/>
</Td>
<Td>
<Asp: Label ID = "ProductNameLabel" runat = "server"
Text = '<% # Eval ("ProductName") %>'/>
</Td>
<Td>
<Asp: Label ID = "CategoryIDLabel" runat = "server"
Text = '<% # Eval ("CategoryID") %>'/>
</Td>
<Td>
<Asp: Label ID = "UnitPriceLabel" runat = "server" Text = '<% # Eval ("UnitPrice") %>'/>
</Td>
</Tr>
</ItemTemplate>
<AlternatingItemTemplate>
<Tr style = "">
<Td>
<Asp: Label ID = "ProductIDLabel" runat = "server" Text = '<% # Eval ("ProductID") %>'/>
</Td>
<Td>
<Asp: Label ID = "ProductNameLabel" runat = "server"
Text = '<% # Eval ("ProductName") %>'/>
</Td>
<Td>
<Asp: Label ID = "CategoryIDLabel" runat = "server"
Text = '<% # Eval ("CategoryID") %>'/>
</Td>
<Td>
<Asp: Label ID = "UnitPriceLabel" runat = "server" Text = '<% # Eval ("UnitPrice") %>'/>
</Td>
</Tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<Table runat = "server" style = "">
<Tr>
<Td>
No data is returned. </Td>
</Tr>
</Table>
</EmptyDataTemplate>
<InsertItemTemplate>
<Tr style = "">
<Td>
<Asp: Button ID = "InsertButton" runat = "server" CommandName = "Insert" Text = "Insert"/>
<Asp: Button ID = "CancelButton" runat = "server" CommandName = "Cancel" Text = "clear"/>
</Td>
<Td>
</Td>
<Td>
<Asp: TextBox ID = "ProductNameTextBox" runat = "server"
Text = '<% # Bind ("ProductName") %>'/>
</Td>
<Td>
<Asp: TextBox ID = "CategoryIDTextBox" runat = "server"
Text = '<% # Bind ("CategoryID") %>'/>
</Td>
<Td>
<Asp: TextBox ID = "UnitPriceTextBox" runat = "server"
Text = '<% # Bind ("UnitPrice") %>'/>
</Td>
</Tr>
</InsertItemTemplate>
<LayoutTemplate>
<Table runat = "server">
<Tr runat = "server">
<Td runat = "server">
<Table ID = "itemPlaceholderContainer" runat = "server" border = "0" style = "">
<Tr runat = "server" style = "">
<Th runat = "server">
ProductID </th>
<Th runat = "server">
ProductName </th>
<Th runat = "server">
CategoryID </th>
<Th runat = "server">
UnitPrice </th>
</Tr>
<Tr ID = "itemPlaceholder" runat = "server">
</Tr>
</Table>
</Td>
</Tr>
<Tr runat = "server">
<Td runat = "server" style = "">
</Td>
</Tr>
</Table>
</LayoutTemplate>
<EditItemTemplate>
<Tr style = "">
<Td>
<Asp: Button ID = "UpdateButton" runat = "server" CommandName = "Update" Text = "Update"/>
<Asp: Button ID = "CancelButton" runat = "server" CommandName = "Cancel" Text = "Cancel"/>
</Td>
<Td>
<Asp: Label ID = "ProductIDLabel1" runat = "server"
Text = '<% # Eval ("ProductID") %>'/>
</Td>
<Td>
<Asp: TextBox ID = "ProductNameTextBox" runat = "server"
Text = '<% # Bind ("ProductName") %>'/>
</Td>
<Td>
<Asp: TextBox ID = "CategoryIDTextBox" runat = "server"
Text = '<% # Bind ("CategoryID") %>'/>
</Td>
<Td>
<Asp: TextBox ID = "UnitPriceTextBox" runat = "server"
Text = '<% # Bind ("UnitPrice") %>'/>
</Td>
</Tr>
</EditItemTemplate>
<SelectedItemTemplate>
<Tr style = "">
<Td>
<Asp: Label ID = "ProductIDLabel" runat = "server" Text = '<% # Eval ("ProductID") %>'/>
</Td>
<Td>
<Asp: Label ID = "ProductNameLabel" runat = "server"
Text = '<% # Eval ("ProductName") %>'/>
</Td>
<Td>
<Asp: Label ID = "CategoryIDLabel" runat = "server"
Text = '<% # Eval ("CategoryID") %>'/>
</Td>
<Td>
<Asp: Label ID = "UnitPriceLabel" runat = "server" Text = '<% # Eval ("UnitPrice") %>'/>
</Td>
</Tr>
</SelectedItemTemplate>
</Asp: ListView>
<Asp: SqlDataSource ID = "SqlDataSource2" runat = "server"
ConnectionString = "<% $ ConnectionStrings: NorthwindConnectionString %>"
SelectCommand = "SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice] FROM [Products] WHERE ([CategoryID] = @ CategoryID)">
<SelectParameters>
<Asp: ControlParameter ControlID = "drop" DefaultValue = "1" Name = "CategoryID"
PropertyName = "SelectedValue" Type = "Int32"/>
</SelectParameters>
</Asp: SqlDataSource>
</Div>
</Form>
</Body>
</Html>

/Web. config
Copy codeThe Code is as follows:
<ConnectionStrings>
<Add name = "NorthwindConnectionString" connectionString = "Data
Source =.; Initial Catalog = Northwind; Integrated Security = True"
ProviderName = "System. Data. SqlClient"/>
</ConnectionStrings>

1. C. Download Resources

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.