I have some values in a DataGridRow
(item Array) and I want to fetch all these values into a string array. How can I achieve this?
DataGridRow row = (DataGridRow)Lst.ItemContainerGenerator.ContainerFromIndex(k);
DataRowView Drv = (DataRowView)row.Item;
DataRow dr = (DataRow)Drv.Row;
var rowAsString = string. Join(", ", dataTable. Rows[0]. ItemArray);
Select(row => row["columnName"]. ToString()). ToArray();
Convert DataTable to Custom class ArrayAsEnumerable(). Select(item => new { fullName = string. Format("{0}, {1}", item["firstName"], item["lastName"]) , Percentage = (Convert. ToInt32(item["Marks"])/100) * 100 }).
var rowAsString = string.Join(", ", dataTable.Rows[0].ItemArray);
No need of any lambda expresion as above.
One possibility is to call dr.ItemArray;
This will get you a object[]
. Then you have to cast each object to string
before you use it.
LINQ adds some sugar:
var stringArray = dr.ItemArray.Cast<string>().ToArray()
var rowAsString = string.Join(", ", dr.ItemArray.Select(c => c.ToString()).ToArray());
This should give you a string with each item in your data row separated by a comma.
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