I have One DataTable with 5 Columns and 10 Rows. Now I want to add one New Column to the DataTable and I want to assign DropDownList value to the New Column. So the DropDownList value should be added 10 times to the New Column. How to do this? Note: Without using FOR LOOP.
For Example: My Existing DataTable is like this.
ID Value ----- ------- 1 100 2 150
Now I want to add one New Column "CourseID" to this DataTable. I have One DropDownList. Its selected value is 1. So My Existing Table should be like below:
ID Value CourseID ----- ------ ---------- 1 100 1 2 150 1
How to do this?
You create DataColumn objects within a table by using the DataColumn constructor, or by calling the Add method of the Columns property of the table, which is a DataColumnCollection. The Add method accepts optional ColumnName, DataType, and Expression arguments and creates a new DataColumn as a member of the collection.
Without For loop:
Dim newColumn As New Data.DataColumn("Foo", GetType(System.String)) newColumn.DefaultValue = "Your DropDownList value" table.Columns.Add(newColumn)
C#:
System.Data.DataColumn newColumn = new System.Data.DataColumn("Foo", typeof(System.String)); newColumn.DefaultValue = "Your DropDownList value"; table.Columns.Add(newColumn);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With