Access to database table structure in a .aspx page
I have a table Software
in my database with the开发者_开发问答 following columns:
id [key]
title
manufacturer
I have a dropdown list in a webform .aspx
file. I want the items in the drop down to be Id
, title
and manufacturer
but I dont want to hard-code the items.
I am going to add more columns in the database table and I want the drop down list items to always remain in sync with the table structure.
How do I accomplish this?
If you use LINQ
:
var columnNames = dataTable1.Columns.OfType<DataColumn>().
Select(c => c.ColumnName).ToList();
comboBox1.DataSource = columnNames;
comboBox1.DataBind();
精彩评论