Вопрос

Help me to sort the below issue.

I have a Dataset and the Dataset has Tables with 'n' number of rows.

I want to display first 5 rows from the table in dataset.

My Page will refresh every 1 minutes.So Whenever my pages is refreshing I need to display the next 5 rows from the dataset.

For Example If my dataset has 15 rows.

When loading the page for first time it should display/get only first 5 rows (1 to 5)from the dataset.

Wehn the page postback/refresh it should dispaly second set of 5 rows (6 to 10) from the dataset.

And again when the page postback it should dispaly thirdset of 5 rows (11 to 15) from the dataset.

Note:I am not using GridView in my webPage. I am using dynamic controls to populate the data's from the dataset.

Thanks,

David

Это было полезно?

Решение

You can clone the original DataTable, and copy whatever rows you want to the cloned DataTable.

private DataTable CopyDataTable(DataTable dt, int index)
{
    DataTable cloneDT = dt.Clone(); // Clone DataTable Structure

    for (int i = index, j = index + 5; i < j; i++)
    {
        DataRow dr = dt.Rows[i];
        cloneDT.Rows.Add(dr.ItemArray);
    }

    return cloneDT;
}

You can invoke the method like this:

GridView1.Datasource  = CopyDataTable(dt, 0); // create new DataTable, with rows 0-4
GridView1.DataBind();

GridView1.Datasource  = CopyDataTable(dt, 5); // create new DataTable, with rows 5-9
GridView1.DataBind();

Другие советы

Set a hiddentfield and set the value as 1. then on pageload inside ispostback=true statement just increment the value of hiddenfield. then pass the value of hiddenfield into the db.

sample code...

    if (isPostBack){
hiddentFieldForTimeCount.value= (int)hiddentFieldForTimeCount.value+1;

}

function CallDB(){
DataTable tbl=function callDB(hiddentFieldForTimeCount.value);
DataBind(tbl);
}

based on the hiddenfield value you can pick the data from database.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top