Solved

populate gridview with dropdown value ISSUE PLEASE HELP

Posted on 2012-04-09
5
224 Views
Last Modified: 2012-04-12
I have a dropdown control that returns all the States.  When the state is selected I would like to show the results in a gridview control or datagrid.  Not sure which one would be the best.

When I tried to use the gridview control it took my value of GA and put it on two rows. I have attached a screenshot of this.  I think i am missing something simple here but not very fimiliar with VB.net and have been learning as I code for this huge project I am so behind on.
Any ideas?  thanks in advance!

Dim state As String = ddlStates.SelectedItem.Value
        lblCityError.Text = ""

        Dim ds As New DataSet()
        Dim dt As New DataTable()
        ds.Tables.Add()

        dt.Columns.Add(New System.Data.DataColumn("State", GetType([String])))

        gvState.DataSource = ddlStates.SelectedItem.Value
        gvState.DataBind()

Open in new window

Enter-Payor-State-OR-Zip-Code-fo.docx
0
Comment
Question by:codeJen
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37838120
Not sure why you are declaring a dataset (neither the datatable but I have made use of it here)
Dim dt As New DataTable()
dt.Columns.Add(New System.Data.DataColumn("State", GetType([String])))
Dim dr As DataRow = dt.NewRow()
dr.ItemArray(ddlStates.SelectedItem.Value)
dt.Rows.Add(dr)
gvState.DataSource = dt

Open in new window

0
 

Author Comment

by:codeJen
ID: 37838206
Yea I'm a nub at this stuff and the company i work for expects us to learn on the fly without training.  I probably tried to many ways and have gotten confused over the course of it.  Anyways I am getting an error on
dr.ItemArray(ddlStates.SelectedItem.Value)

Says: property access must assign to the property or use its value?
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37838267
Applyt the ToString method,e.g
dr.ItemArray(ddlStates.SelectedItem.Value.ToString)

Open in new window

or do:
dr.Item(0) = ddlStates.SelectedItem.Value.ToString

Open in new window

0
 

Author Closing Comment

by:codeJen
ID: 37838300
I used dr.Item(0) = ddlStates.SelectedItem.Value.ToString and that did the trick!    Thank you soooooooo much!! You're a time saver! :)
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37838358
Bear in mind to select the correct zone when asking a question. If you'd put this in Visual Basic .NET, you would have received an answer quicker!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now