Solved

populate gridview with dropdown value ISSUE PLEASE HELP

Posted on 2012-04-09
5
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…

738 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