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" >
<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= "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