You don't need a data table to bind - you just need something like a list / enumerable. For example, if you know the line number:
DataRowView row = dt.DefaultView[1]; // second row detailsView1.DataSource = new DataRowView[] {row}; detailsView1.DataBind();
Note that we must use a DataRowView (rather than a DataRow ) to get only run-time properties (i.e. data from columns). If you have a DataRow , this approach can be easily wrapped in a utility method, for example, an extension method:
public static DataRowView[] ForBinding(this DataRow row) { foreach (DataRowView rowView in row.Table.DefaultView) { if (ReferenceEquals(rowView.Row, row)) { return new DataRowView[] { rowView }; } } throw new ArgumentException("Row not found in the default view", "row"); }
with:
detailsView1.DataSource = row.ForBinding(); detailsView1.DataBind();
source share