Hi,
Try below Extension method.
public static class Extensions
{
public static string GetCommaSeparatedValue(this DataTable value, String columnfilter, String filterParam, String columnName)
{
string retVal = String.Empty;
if (value.Rows.Count > 0)
{
var rowColl = value.AsEnumerable();
retVal = String.Join(",",(from r in rowColl where r.Field<string>(columnfilter) == filterParam select r.Field<string>(columnName)));
}
return retVal.ToString();
}
}
</string></string>
Now use this to get comma separated values.
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Movies", typeof(String)));
dt.Columns.Add(new DataColumn("TvSeries", typeof(String)));
dt.Rows.Add("1", "Prison Break");
dt.Rows.Add("1", "How i Met your mother");
dt.Rows.Add("3", "Lost");
dt.Rows.Add("2", "Prison Break");
var str = dt.GetCommaSeparatedValue("Movies", "1", "TvSeries");
you can use this anywhere windows or asp.net.
As this sample code you can refine according to your need.
Hope this helps!