views:

71

answers:

2

Hello everyone i need help. Ive been having this problem for almost a day now. dropdown list won't populate from database

Below is the code i am using:

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PhotoAlbum.aspx.vb" Inherits="PhotoAlbum" %>

Members Of Ephesians 5:10 Photo Album!
<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">

</asp:Content>

i need help pls

A: 

I quickly created a test page with following code, it works for 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"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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

Screenshot:

alt text

Lee Sy En
This problem has taken all of my time still to no avail. I compared it with ur code and everything looks good, when i run the application i couldn't see the values. It's weird because i am studying this project from a book called Sams Teach yourself ASP.NET 2.0. It's a step by step example. My database and everything looks good but the drop down control won't populate. Is there any other suggestion? Again the code is above. Can u provide me with a vb.net code>
onfire4JesusCollins
There is no difference between VB and C#'s aspx page, except my CodeFile is pointing to .cs and yours is .vb. Any error shown on your screen or it just loaded with a blank page? Are you able to print screen and paste it here?
Lee Sy En
How do u take screenshot. This is the third day im still having this problem. Ive done everything i can. The dropdown list on the other pages works but this one does not.
onfire4JesusCollins
Hello i got this code below from a website after searching for dropdown list will not populate values from a database:
onfire4JesusCollins
Imports System.DataImports System.IOImports System.Data.SqlClientPartial Class PhotoAlbum Inherits System.Web.UI.Page Dim ds As Object Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim sql As String = "[CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]" categories.DataSource = ds categories.DataTextField = "Name" categories.DataValueField = "CategoryID" End SubEnd Class do i need any modification of the code. it won't still work for me
onfire4JesusCollins
+1  A: 

set AutoEventWireup="true" in page directive

ImadArif