Asp. NET ListView (List view) the use of the foreground binding source code _ Practical Skills

Source: Internet
Author: User
1.A, Operation effect Chart



1.B, source code
Copy Code code 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 ">

<title> Untitled Page </title>

<body>
<form id= "Form1" runat= "Server" >
<div>
Please select a large 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>
Products under this category: <br/>
<asp:listview id= "LVW" runat= "Server" datakeynames= "ProductID"
Datasourceid= "SqlDataSource2" >
<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 returned. </td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style= "" >
<td>
<asp:button id= "Insertbutton" runat= "server" commandname= "Insert" text= "inserts"/>
<asp:button id= "CancelButton" runat= "Server" commandname= "Cancel" text= "purge"/>
</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" >
&LT;TR runat= "Server" >
&LT;TD runat= "Server" >
<table id= "Itemplaceholdercontainer" runat= "server" border= "0" style= "" >
&LT;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>
&LT;TR runat= "Server" >
&LT;TD runat= "Server" style= "" >
</td>
</tr>
</table>
</LayoutTemplate>
<EditItemTemplate>
<tr style= "" >
<td>
<asp:button id= "UpdateButton" runat= "Server" commandname= "Update" text= "Updates"/>
<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>


/web.config
Copy Code code as follows:

<connectionStrings>
<add name= "NorthwindConnectionString" connectionstring= "Data
Source=.;i Nitial catalog=northwind;integrated Security=true "
Providername= "System.Data.SqlClient"/>
</connectionStrings>

1.C, Resource download

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.