Insert empty datarow into datatable
-
Hi all, I am knowing how to insert datarow into datatable by using method below:
DataTable dt = new DataTable();
DataRow myNewRow;
myNewRow = dt.NewRow();
myNewRow[0] = 1;
myNewRow[1] = "johndoe" ;
dt.Rows.Add(myNewRow);But in my case, i have upto 20 columns for a row data.Then i don't want to use the For...Loop to declare each column's value. So, may i know its there have any others alternative to insert a empty row into datatable? Note: Actually at the end, i will bound this datatable to a dropdwonlist. any helps are welcome Thanks in advance regards cocoonwls
-
Hi all, I am knowing how to insert datarow into datatable by using method below:
DataTable dt = new DataTable();
DataRow myNewRow;
myNewRow = dt.NewRow();
myNewRow[0] = 1;
myNewRow[1] = "johndoe" ;
dt.Rows.Add(myNewRow);But in my case, i have upto 20 columns for a row data.Then i don't want to use the For...Loop to declare each column's value. So, may i know its there have any others alternative to insert a empty row into datatable? Note: Actually at the end, i will bound this datatable to a dropdwonlist. any helps are welcome Thanks in advance regards cocoonwls
Hi all, I got a solution base on my case(in my case i want bind this dt to dropdownlist). In the dropdownlist control, firstly set appenddatabounditems to true, then add a empty items into collection. Then, at .cs just bind the data into that dropdownlist. Off course you have set the datatextfeild and datavaluefeild. :laugh: thanks for those view my question~ regards lswang