ASP.NET - datatable bind into repeater control

Asked By Kaleem Khan on 08-Feb-10 02:15 AM

i have .net datatable in that table 10 records are there,

i want to bind only 4th  record  only

please help

Huggy Bear replied to Kaleem Khan on 08-Feb-10 02:52 AM
For this, you can use the DefaultView of your datatable to bind to the GridView. In order to filter the record make sure that you set the RowFilter property of the DataView properly and simple bind the DataView to the GridView control. Below is the code

//Assuming that dataTable already has the retrieved data
//in the dataTable add a column named RowIndex which holds the respective row's index as value

DataView dv = dataTable.DefaultView;
//Set the row filter
dv.RowFilter = string.Format("RowIndex={0}", 4);
//Set the filtered view as datasource
GridView1.DataSource = dv;
GridView1.DataBind();


For more information of the RowFilter property check http://authors.aspalliance.com/aspxtreme/sys/data/dataviewclassrowfilter.aspx.
Sandra Jain replied to Kaleem Khan on 08-Feb-10 03:32 AM
You can bind the 5th row to the datatable by using:

Dim ds as new dataset
ds=ds.Tables(0).Rows(3)
No bind this dataset to the datatable.
Web Star replied to Kaleem Khan on 08-Feb-10 11:59 AM

u just filter 4th row from your datatable to dataview and bind to repeater control.

DataView dv = dataTable.DefaultView;
//Set the row filter
dv.RowFilter = string.Format("RowIndex={0}", 4);
Repeater1.DataSource = dv;
Repeater1.DataBind();