2010-10-01 112 views
1

大家好,我需要幫助。我已經有這個問題差不多一天了。下拉列表將不會從數據庫下拉列表不會填充數據庫中的值

下面填充是代碼我使用:

<%@頁標題= 「」 LANGUAGE = 「VB」 的MasterPageFile = 「〜/的Site.Master」 AutoEventWireup =「假「的CodeFile =」 PhotoAlbum.aspx.vb」繼承= 「天地我的相簿」 %>

成員以弗所書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 = 「名稱」 DataValueField = 「類別ID」>

</asp:Content> 

我需要幫助請

回答

0

我很快就創建了下面的代碼測試頁,它適用於me:

<%@ 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:

alt text

截圖:

alt text

+0

這個問題已經採取了所有我的時間依然無果。我將它與我的代碼進行了比較,一切都很好,當我運行應用程序時,我看不到值。這很奇怪,因爲我正在從一本名爲Sams的書中學習這個項目。自學ASP.NET 2.0。這是一步一步的例子。我的數據庫和一切看起來不錯,但下拉控制不會填充。還有其他建議嗎?代碼再次在上面。你可以給我一個vb.net代碼> – onfire4JesusCollins 2010-10-01 23:29:35

+0

除了我的CodeFile指向.cs和你的.vb之外,VB和C#的aspx頁面沒有區別。屏幕上顯示的任何錯誤,或只是加載了空白頁面?你能打印屏幕並粘貼在這裏嗎? – bla 2010-10-02 03:23:44

+0

你如何截圖?這是我仍然有這個問題的第三天。我已盡我所能。其他頁面上的下拉列表可以正常工作,但這不是。 – onfire4JesusCollins 2010-10-02 20:49:36

1

集AutoEventWireup = 「真」,在頁面指令