dataset and datalist

mark222
mark222 used Ask the Experts™
on
dear experts,
i want to loop over dataset and display part of the data in datalist ,it is like paging but i dont want to connect DB again to get second page data, , how i can loop over dataset to get part of the data.
regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Rahul Goel ITILSenior Consultant - Deloitte

Commented:

DataSet ds = new DataSet();
        DataTable dt = ds.Tables["TableName"];
        List<DataRow> rows =new List<DataRow>(dt.Select("Condition", "SortCondition"));
        rows.ForEach(delegate(DataRow row)
        {
            // DoAction
        });

Open in new window

Author

Commented:
thank you rahu, this mean that the filtered rows should be with condition, but i want to display the first  50 then the second 50 without any condition.
int TotalPages;
int StartRecord = 0;

//Calculate total no of Page for the given page size here for example i am doing for pagesize 50
TotalPages = DataSet1.Tables[0].Rows.Count / 50

// Set ViewState("Pageno")  =  1  

DataTable dt = DataSet1.Tables[0];

if(ViewState("StartRecord") == null)
{
ViewState("StartRecord") = 0
}

for(int i = StartRecord;i<50;i++)
{
  dt.Rows.Add(ds.Tables[0].Rows[i])
}

StartRecord  =  Int32.Parse(ViewState("StartRecord").ToString());

if(StartRecord <= DataSet.Tables[0].Rows.Count)
ViewState("StartRecord") = Int32.Parse(ViewState("StartRecord").ToString()) + PageSize
else
StartRecord = 0;

GridView1.DataSource = new DataView(dt)
GridView1.DataBind();





How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
thank you Muralidharanp: ,but i have important q,i noticed all custom paging technique do the same  job, what i mean that when you press to go to anather page you will go second time to Database to fill Dataset, what i think about is to fill the dataset one time then you  travel through the data without going to DB for every page. is it possible?
Yes it is possible if u store the dataset into ViewState . during postback we can get data from ViewState Variable instead of fetching records again from Db.
Yes it is possible if u store the dataset into ViewState . during postback we can get data from ViewState Variable instead of fetching records again from Db. Sorry for lated reply.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial