大家好,我需要帮助。我已经有这个问题了近一天了。下拉列表不会从数据库中填充
以下是我正在使用的代码:
<%@ Page Title =“”Language =“VB”MasterPageFile =“〜/ Site.master”AutoEventWireup =“false”CodeFile =“PhotoAlbum.aspx.vb”Inherits =“PhotoAlbum”%>
以弗所书的成员5:10写真集!
<asp:SqlDataSource ID="categoriesDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]">
<SelectParameters>
<asp:QueryStringParameter Name="UserId" QueryStringField="ID"/>
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<h1 style="font-weight:bold">Filter Pictures By Category:
<asp:DropDownList ID="categories" runat="server"
AppendDataBoundItems="True"
DataSourceID="categoriesDataSource" AutoPostBack="True"
DataTextField =“Name”DataValueField =“CategoryID”&gt;
</asp:Content>
我需要帮助pls
答案 0 :(得分:1)
在页面指令
中设置AutoEventWireup =“true”答案 1 :(得分:0)
我很快创建了一个包含以下代码的测试页面,它对我有用:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testddl.aspx.cs" Inherits="testddl" %>
<!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>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="CategoryName"
DataValueField="CategoryID">
</asp:DropDownList>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TESTDBConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] WHERE ([UserID] = @UserID)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="UserID" QueryStringField="ID"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
dbo.Categories:
截图: