Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 8th, 2007, 02:33 AM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default help with datatextfield in the dropdownlist

i created a data entry page and have a dropdownlist. the values would be sent to the next page o be published to a report. how can i convert values inserted with dropdownlists so i can display the text in the datatextfield to be bind with a label

Any idea how this conversion can be done?

Dim objdr As SqlDataReader
            Try
                conn.Open()
                objdr = objCmd4.ExecuteReader()
               dropdownlist.DataSource = objdr
               dropdownlist.DataTextField = "Officename"
                dropdownlist.DataValueField = "OfficeCode"
                dropdownlist.DataBind()
                objdr.Close()
                Dim item As ListItem = New ListItem("choose", "-1")
                Me. dropdownlist.Items.Insert(0, item)
            Catch err As Exception
                Response.Write("error: " & err.Message())
                Response.Redirect("errorpage.aspx")
            Finally
                conn.Close()
            End Try[/SIZE]

the dropdown list get feed form a table and inserted into another tables to do some processing. how can i link these tables to get the string bind to a label or textbox
 
Old November 8th, 2007, 09:28 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Are you trying to get the text value of the item selected in the dropdownlist into your label or textbox or are you trying to databind information to a label or textbox?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 8th, 2007, 12:12 PM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes i wanted to get the text value of the selected dropdownlist :

"Officename"

and bind it to a label in the next page... once the user hit the submit button

 
Old November 8th, 2007, 12:32 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You will need to use a session value to persist the value to the next page but you would get the value like this:

string foo = dropdownlist.SelectedItem.Text;

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 8th, 2007, 01:12 PM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks 4 the idea mate, but i'm thinking of implementing conversion function on the page something like this:

  Dim myConnection As New SqlConnection("data source=xxxx;initial catalog=xxxx;user id=sa;password=xxxxxx")
        myConnection.Open()
        Dim SQL As String
        SQL = ("SELECT OfficerType FROM OfficerTable where KodOfficer=" & _string & " ")
        Dim myCommand As New SqlCommand(SQL, myConnection)
        Dim myReader As SqlDataReader
        myReader = myCommand.ExecuteReader()
        myReader.Read()
        myConnection.Close()

and then bind them to a string .... something like this:

'dim stringResult as string
'stringResult = myReader(0).ToString

care to show me how to do this?


 
Old November 8th, 2007, 01:37 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well your logic won't change. Instead of _string in your above code use dropdownlist.SelectedItem.Text also, I would use ExecuteScalar() to return your value rather then opening a datareader just to get one value.

Here is an example of using ExecuteScalar()

http://www.aspfree.com/c/a/ASP-Code/...ed-Procedures/



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist sumith ASP.NET 1.0 and 1.1 Professional 1 February 23rd, 2007 09:11 AM
DropdownList Venkatesan ASP.NET 1.0 and 1.1 Basics 1 December 11th, 2006 11:03 AM
DropDownList chiraagb VS.NET 2002/2003 5 June 15th, 2004 03:12 AM
dropdownlist msrnivas .NET Web Services 0 March 4th, 2004 11:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.