Click here to Skip to main content
16,021,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on asp.net i have created a webform. I placed 2 dropdownlist controls on it.

1. In the first dropdownlist i saved 4 values(Country,State,District,Region) these four are the table names which present in my sqlserver2008 database.

2. I want to display the first column values(Country_ID or State_ID or District_ID or Region_ID) in the 2nd dropdownlist.
Here the value in 2nd dropdownlist should fill depend upon the selected item in 1st dropdownlist.

Question:-

If i select Country in 1st dropdownlist then the first column(Country_ID)values present in the Country table should fill.
How can i write the query statement to select first column of selected table value in my c# code behind file.

Thanks
Raj
Posted

This gets the first column in the table (or null if there are no columns).

C#
DataColumn firstColumn = dataTable.Columns.FirstOrDefault();
string name = "UNKNOWN";
if (firstColumn != null)
{
    name = firstColumn.ColumnName;
}
 
Share this answer
 
v3
 
Share this answer
 

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