0
我想使用下拉菜單來過濾gridview,但看起來正在選擇的下拉列表不會讓它到我的SqlDataSource控件。 (我是新來的asp.net,這是我正在學習的教程。)使用DropDown控件無法過濾GridView
當我刪除SelectParameters部分並將一個有效的LastName插入到gridview的select語句的where子句中時,我得到像我所期望的那樣過濾gridview,但是當我從下拉列表中選擇一個名字時它不起作用。
這可能是一個VS版本的東西。我使用VS 2010(W/.NET 3.5),其中書中使用VS 2008
代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SqlDataSourceParameters_3.aspx.cs" Inherits="SqlDataSourceWizard" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:SqlDataSource ID="CustomersDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
SelectCommand="SELECT [FirstName], [LastName], [EmailAddress], [ModifiedDate] FROM [Person].[Contact] WHERE ([LastName] = @LastName)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="LastName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="CustomerGridView" runat="server" AutoGenerateColumns="False"
DataSourceID="CustomersDataSource" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"
SortExpression="EmailAddress" />
<asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate"
SortExpression="ModifiedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="StaffDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString2 %>"
SelectCommand="SELECT DISTINCT [LastName] FROM [Person].[Contact] ORDER BY 1"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="StaffDataSource" DataTextField="LastName"
DataValueField="LastName">
</asp:DropDownList>
</form>
</body>
</html>
我錯過了教程中的一個頁面,我打印出來並沒有意識到我錯過了AutoPostBack =「true」。我應該刪除這個問題嗎? – TimeTrap 2012-04-27 14:26:42