Welcome to Dream.In.Code
Getting Help is Easy!

Join 98,764 Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 1,044 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert

Register to Make This Box Go Away!


DropDownList

 
Reply to this topicStart new topic

DropDownList

Najla
post 9 May, 2008 - 04:45 PM
Post #1


New D.I.C Head

*
Joined: 25 Mar, 2008
Posts: 10

hi..
I'm tyring to make the list items of my dropdownlist loaded from the database according to a query written in (page_load )

so I tried the following codebut it didn't work..
I need your help please...
CODE

Imports System.IO
Imports System.data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim myConnection As SqlConnection
        Dim myTransaction As SqlTransaction = Nothing
        Dim reader As SqlDataReader
' select personal collection names owned by a specific user to be  put in 'the dropdownlist
        Dim cmd As String = "SELECT PCName FROM PersonalCollection WHERE UserId = edcb1927-8a53-4c11-84d2-7d6843b7035a"

        Try
            myConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnectionString1").ToString())
            myConnection.Open()
            myTransaction = myConnection.BeginTransaction()

            Dim myCommand As SqlCommand = New SqlCommand(cmd, myConnection, myTransaction)

            reader = myCommand.ExecuteReader()
            reader.Read()
            DropDownList1.DataSource = reader(0).ToString()

            reader.Close()
            myTransaction.Commit()

        Catch ex As Exception
            If (myTransaction.Equals(Nothing) = False) Then
                myTransaction.Rollback()

            End If
        Finally
            myConnection.Dispose()

        End Try

    End Sub
End Class
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 9 May, 2008 - 07:11 PM
Post #2


using Coding.God;

Group Icon
Joined: 26 Jul, 2007
Posts: 6,569



Thanked 24 times

Dream Kudos: 7350

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#

My Contributions


Can you please define "But it didn't work". Are you receiving any errors, if so what are they? What is this code doing versus what you want/need it to do? These are vital pieces of information needed to help us help you. You cannot just post code and expect us to figure out what you want or what's going wrong smile.gif
User is online!Profile CardPM

Go to the top of the page

Najla
post 10 May, 2008 - 02:56 AM
Post #3


New D.I.C Head

*
Joined: 25 Mar, 2008
Posts: 10

QUOTE(PsychoCoder @ 9 May, 2008 - 07:11 PM) *

Can you please define "But it didn't work". Are you receiving any errors, if so what are they? What is this code doing versus what you want/need it to do? These are vital pieces of information needed to help us help you. You cannot just post code and expect us to figure out what you want or what's going wrong smile.gif



I am trying to develop a website (a digital repository for learning objects) ,,this site has a log in capablity ,,so each user has its own profile.
and can create one or more personal collections.
personal collection= collection has a name and attached to a user and contains a number of learning objects chosen by that user

in the database there are two tables for personal collections.
1- PersonalCollection (PCID, PCName,UserId)
2- PersonalCollection_LO (PCID,LOID)
LO=learning object

each user after browsing any learning object will see at the bottom of the page , a dropdownlist that contains his/her previosly created personal collections to choose one of them and click add ,,so this browsed learning object will be contained in the selected personalcollection


There was no errors in my code but after running the page, the dropdownlist is empty
ok,, I want to know how to make the list items of a dropdownlist dynamic depending on a user ID ,,so the items of this dropdownlist will change depending on the current logged in user for example:

-Amanda will see her personal collection names in this drop downlist:
my collection1
amanda1
amanda2

- Jhon will see:
collection
jhon2
my collection3

Actully I will use
CODE

Dim user As MembershipUser = Membership.GetUser()
User.ProviderUserKey.ToString()

to get the current user Id but in the previous code I put a specific USER_ID just to test the code..

thank you very much PsychoCoder..
I hope it is clear now smile.gif

This post has been edited by Najla: 10 May, 2008 - 03:04 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 7/20/08 02:40PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->