Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I download a vb file.
This vb file create the table structure for the 50 united states.

some example code.

VB
usaStatesDataTable = New DataTable
            usaStatesDataTable.Columns.Add(STATE_ABBREVIATION_COL_NAME, Type.GetType("System.String"))
            usaStatesDataTable.Columns.Add(STATE_COL_NAME, Type.GetType("System.String"))
            usaStatesDataTable.Columns.Add(STATE_COL_NAME_UPPER, Type.GetType("System.String"))
            'TODO: Localization: US State names
            ' Add the states rows into the dataset.
            row = usaStatesDataTable.NewRow()
            row(STATE_ABBREVIATION_IDX) = "AK"
            row(STATE_IDX) = "Alaska"
            row(STATE_UPPER_IDX) = "ALASKA"
            usaStatesDataTable.Rows.Add(row)
            row = usaStatesDataTable.NewRow()
            row(STATE_ABBREVIATION_IDX) = "AL"
            row(STATE_IDX) = "Alabama"
            row(STATE_UPPER_IDX) = "ALABAMA"
            usaStatesDataTable.Rows.Add(row)
            row = usaStatesDataTable.NewRow()
            row(STATE_ABBREVIATION_IDX) = "AR"
            row(STATE_IDX) = "Arkansas"
            row(STATE_UPPER_IDX) = "ARKANSAS"
            usaStatesDataTable.Rows.Add(row)
            row = usaStatesDataTable.NewRow()
            row(STATE_ABBREVIATION_IDX) = "AZ"
            row(STATE_IDX) = "Arizona"
            row(STATE_UPPER_IDX) = "ARIZONA"
            usaStatesDataTable.Rows.Add(row)


How do I access this file to populate a drop down list to show all the states.
Posted

If the DataTable you have shown in your code above is exposed by a class (via property, function or field) then all you have to do is refernence the library (dll) or the executable (exe) in your project and you can use it like any other type and then get at the table.
If the structure is only used internally (private etc.) you might think about refactoring the code and wrap the code you're after in an own class.

Cheers,

Manfred
 
Share this answer
 
v2
Comments
Dalek Dave 27-Dec-10 18:19pm    
Good answer.
Set the dropdown's DataSource property to your DataTable object, then assign the DisplayMember and ValueMember properties appropriately.
 
Share this answer
 
Comments
Dalek Dave 27-Dec-10 18:19pm    
Good call.
FYI...about Class
Creating Class File in Asp.Net 2.0 for Database Manipulations[^]

Like below
C#
ClsStates objStates=new ClsStates();//Your class file
DataTable usaStatesDataTable = new DataTable();//Datatable
usaStatesDataTable = objStates.GetStates();//Your data in your class //Here GetStates() will be return your data as a Datatable which you have mentioned
ddlStates.DataSource = usaStatesDataTable;//Result datatable which contains data
ddlStates.DataValueField = "StateID";
ddlStates.DataTextField = "StateName"
ddlStates.DataBind();
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 27-Dec-10 14:29pm    
I'll give you five for showing him how to populate the DropDownList eventhough his question seemed to revolve more around how to access the already populated DataTable. :)
Marc A. Brown 27-Dec-10 14:38pm    
Manfred, I read the question the same way as thatraja. "How do I acceess this file to populate a drop down list..." sounds like the OP didn't know how to do what thatraja and I both stated in our answers. :) It's possible that both of us were wrong though. :D
thatraja 27-Dec-10 14:43pm    
Hey guys, Just now I realized my mistake. I don't know how i missed 'access the file' in the question :) Anyway I'll update the thing. cheers :D
thatraja 27-Dec-10 14:53pm    
Thank you Manfred.
Manfred Rudolf Bihy 27-Dec-10 15:08pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900