[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Retrieve value from a Dataview

Asked by Robear423 in .NET, Miscellaneous Web Development

Tags: dataview, dvstate, retrieve, value

good day, As this is my first .Net prj., pls excuse my ignorance. I need to fill a textbox according to the value the user clicks in a dropdownlist box. the dropdownlist box is filled via a dataview. asp.net & sql 2000

Ex.

dropdownlist : (user chooses)         'AUSTIN'

(then according to the City)
textbox1: 'TEXAS'

THE DATA SIDE
------------------
I have 2 tables called StateMaster & CityMaster
the StateMaster table has the fields                                               the CityMaster table has the fields
mst_StateCode   (char, 2)(PK)                                                      mst_StateCode   (char, 2)(FK)
mst_StateName  (varchar, 50)                                                      mst_CityCode (varchar, 10)(PK)
mst_StateStatus (char, 1)                                                            mst_CityName (varchar, 50)

THE FORM SIDE
------------------
ddlcity1
textbox1  

The plan basically is to fill in the textbox with the state name based on the selection in the ddlcity1 dropdownlist.

HERE IS THE CODE
----------------------

   Private dvProducts As DataView
    Private dvState As DataView
    Public strMsg As String
    Public strErrorMsg As String

    Protected Const SQL_CONNECTION_STRING As String = _
    "Server=SQLSERVER;Initial Catalog=database;UID=tempuser;password=tempuser"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim scnnNW As New SqlConnection(SQL_CONNECTION_STRING)

        Dim strSQL As String = _
        "SELECT * FROM CityMaster WHERE mst_CityStatus=0 order by mst_CityCode"

        Dim scmd As New SqlCommand(strSQL, scnnNW)

        ' A SqlDataAdapter uses the SqlCommand object to fill a DataSet.
        Dim sda As New SqlDataAdapter(scmd)

        ' Create and Fill a new DataSet.
        Dim ds As New DataSet
        sda.Fill(ds)

        If Not IsNothing(Cache("dvProducts")) Then
            ' All items in the cache are of type Object, so you have to explicitly
            ' cast it before working with it further.
            dvProducts = CType(Cache("dvProducts"), DataView)
        Else ' DataView was not found in the cache.
            ' Create a new DataView.
            dvProducts = ds.Tables(0).DefaultView
            ' Put the new DataView into the Cache
            Cache("dvProducts") = dvProducts
        End If

        With ddlCity1
            .DataSource = dvProducts
            .DataValueField = "mst_StateCode"
            .DataTextField = "mst_CityName"
            .DataBind()
        End With
        ddlCity1.Items.Insert(0, New ListItem("--------Select One--------", "0"))


        strSQL = "SELECT * FROM StateMaster WHERE mst_StateStatus=0 order by mst_StateCode"
        Dim scmd1 As New SqlCommand(strSQL, scnnNW)
        Dim sda1 As New SqlDataAdapter(scmd1)

        ' Create and Fill a new DataSet.
        Dim ds1 As New DataSet
        sda1.Fill(ds1)
        If Not IsNothing(Cache("dvState")) Then
            dvState = CType(Cache("dvState"), DataView)
        Else
            dvState = ds.Tables(0).DefaultView
            Cache("dvState") = dvState
        End If

    End Sub


    Private Sub ddlCity1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCity1.SelectedIndexChanged

        Dim i As Integer
        dvState.Sort = "mst_StateCode"
        TextBox1.Text = ddlCity1.SelectedItem.Value
        i = dvState.Find(ddlCity1.SelectedValue)
        TextBox1.Text = CStr(dvState.Item(i)("mst_StateName"))

    End Sub

but it dosent work. When i select a value in the dropdownlist, i get the value of the first item in the ddlcity1 - even though I've selected some other value.

Pls help.
[+][-]09/14/04 02:30 PM, ID: 12059540Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: .NET, Miscellaneous Web Development
Tags: dataview, dvstate, retrieve, value
Sign Up Now!
Solution Provided By: Zonebit
Participating Experts: 1
Solution Grade: A
 
[+][-]09/15/04 06:06 AM, ID: 12064089Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/04 09:37 AM, ID: 12506814Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11/11/04 09:11 AM, ID: 12556646Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11/15/04 12:49 AM, ID: 12582016Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92