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

Join 99,785 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,547 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Use Dropdownlist display picture in imagebutton

 
Reply to this topicStart new topic

Use Dropdownlist display picture in imagebutton, On Line Voting System

ryan john majarais
post 3 May, 2008 - 10:38 AM
Post #1


New D.I.C Head

*
Joined: 3 Apr, 2008
Posts: 5


My Contributions


whatsthat.gif my website is voting system i have a dropdownlist inside the dropdownlist is a data and a list of surname if i select one his/her picture will display in the imagebutton. my code wont work. what is wrong??
CODE

Imports System.Data
Imports System.Data.Sql

Partial Class VotingSystem_Candidates
    Inherits System.Web.UI.Page

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        Dim connString As String = _
        ConfigurationManager.ConnectionStrings("connstr").ConnectionString

        Using cnn As New SqlClient.SqlConnection(connString)
            Const sql As String = "select forSurname from VotingCandidateRegistration"


            Dim myCommand As New SqlClient.SqlCommand(sql, cnn)
            Dim myDataset As New DataSet

            Try
                cnn.Open()

            Catch ex As Exception
                MsgBox(ex.ToString)

            End Try

            Dim myAdapter As New SqlClient.SqlDataAdapter(myCommand)
            myAdapter.Fill(myDataset)

            DrpPresident.DataSource = myDataset
            DrpPresident.DataBind()

            Dim i As Integer

            For i = 0 To DrpPresident.Items.Count - 1

                DrpPresident.Items.Add(myDataset.Tables(0).Rows(0).Item("forsurname").ToString)


Next

        End Using

Protected Sub DrpPresident_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DrpPresident.SelectedIndexChanged
        Dim connString As String = _
                        ConfigurationManager.ConnectionStrings("connstr").ConnectionString
        Dim cnn As New SqlClient.SqlConnection(connString)

        
        Try
            cnn.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Dim sql As String



        sql = "SELECT forSurname from votingCandidateRegistration where  forStdntNo like  '" & DrpPresident.SelectedValue & "'"
        'Dim sql As String = "INSERT INTO StdntLogin & #40;StdntUsername,StdntPassword,StdntFname,StdntLname,StdntEmailadd,StdntSquesti
on,StdntSanswer,StdntNumber,StdntCourse,StdntGender,Category) VALUES ('" & txtuser.Text & "', '" & txtpassword.Text & "','" & txtfirstname.Text & "', '" & txtlastname.Text & "','','','','" & txtstudentno.Text & "','','', 'admin') "


ImgPresident.ImageUrl = "~/Pictures/ulosoto.JPG"


        Dim cmd As New SqlClient.SqlCommand(sql, cnn)
Dim myDataSet As New DataSet

        Dim myAdapter As New SqlClient.SqlDataAdapter(cmd)
        myAdapter.Fill(myDataSet)

    End Sub


This post has been edited by jayman9: 3 May, 2008 - 10:51 AM
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 3 May, 2008 - 11:43 PM
Post #2


using Coding.God;

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



Thanked 26 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


Well I see you're binding your DropDownList to your DataSet, then you're trying to add items to it from the DataSet (the one it's already bound to). You either want to bind or add like you're doing in your For loop, not both. Also, all your work is being done outside your Try...Catch block which doesnt make any sense. The Try...Catch block is for trapping any exceptions that may occur.


vb


Imports System.Data
Imports System.Data.Sql

Partial Class VotingSystem_Candidates
Inherits System.Web.UI.Page

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
Try
Dim connString As String = _
ConfigurationManager.ConnectionStrings("connstr").ConnectionString

Using cnn As New SqlClient.SqlConnection(connString)
Const sql As String = "select forSurname from VotingCandidateRegistration"

Dim myCommand As New SqlClient.SqlCommand(sql, cnn)
Dim myDataset As New DataSet
cnn.Open()
Dim myAdapter As New SqlClient.SqlDataAdapter(myCommand)
myAdapter.Fill(myDataset)

For i As Integer = 0 To myDataset.Tables(0).Rows.Count - 1
DrpPresident.Items.Add(myDataset.Tables(0).Rows(0).Item("forsurname").ToString)
Next
End Using
Catch ex As Exception
MsgBox(ex.ToString)

End Try
End Sub


Protected Sub DrpPresident_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DrpPresident.SelectedIndexChanged
Try
Dim connString As String = _
ConfigurationManager.ConnectionStrings("connstr").ConnectionString
Dim cnn As New SqlClient.SqlConnection(connString)
cnn.Open()
Dim sql As String
sql = "SELECT forSurname from votingCandidateRegistration where forStdntNo like '" & DrpPresident.SelectedValue & "'"
ImgPresident.ImageUrl = "~/Pictures/ulosoto.JPG"
Dim cmd As New SqlClient.SqlCommand(sql, cnn)
Dim myDataSet As New DataSet
Dim myAdapter As New SqlClient.SqlDataAdapter(cmd)
myAdapter.Fill(myDataSet)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub



Doing it this way will at least let you know if you have error's that are occurring.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 7/25/08 01:28AM

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
-->