积极答复者
DropDownList显示不出内容

问题
-
请教各位大牛:
我用SqlDataSource 控件访问数据库并且命名该控件为SqlDataSource1,然后拖进来一个
DropDownList控件,将其数据源设置为SqldataSource1,打算让DropDownList能显示取回的数据的
一个字段,代码如下:
但是在浏览器查看时下拉列表没有显示任何内容:
求解·!!!麻烦了。。。。
- 已移动 ThankfulHeart 2012年9月1日 2:41 ASP.NET问题 (发件人:.NET Framework 一般性问题讨论区)
答案
全部回复
-
%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
SelectCommand="SELECT * FROM Customers WHERE Country = @CountryParam">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CountryParam"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="CustomerID"
DataValueField="CustomerID">
</asp:DropDownList>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName"
SortExpression="ContactName" />
<asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle"
SortExpression="ContactTitle" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Region" HeaderText="Region"
SortExpression="Region" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode"
SortExpression="PostalCode" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
</Columns>
</asp:GridView>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>这是源代码,设计页面如下:
本打算通过选取下拉列表中显示的国家,然后GridView自动显示所有该国家客户的资料的。可以确定的是数据源存在,因为仅仅用GridView显示表Customers所有数据时没有问题。麻烦了。。。。。。。。。。。。。。。