about datalist and access datasource

M

miladhatam

hi
how can i show every 10 records of my db in datalist in several page
i want to get it the paging property
i even wrote this code
AccessDataSource1.SelectCommand = "SELECT * FROM table1 where id
between " + (page - 1) * 10 + " and " + (page * 10 - 1) ;
but it works when my 'id' have a correct sequence of number
you know for example when you have 3 records with id 1,2,3 and when
you delete second record after that you have 2 records but your new
second record's id is still 3
and it make a mistake

what is your soloution for paging the datalist?
thanks
 
M

miladhatam

i did it myself
protected void Page_Load(object sender, EventArgs e)
{
int range = 2;
int p = Convert.ToInt16(Request["page"].ToString());
if ( p ==0)
p=1;
if (DataList1.Items.Count % range > 0)
{

numeric1.listSize = (DataList1.Items.Count / range) + 1;
}
if (DataList1.Items.Count % range == 0)
{
numeric1.listSize = (DataList1.Items.Count / range);

}
if (p == 1)
{
for (int i = range; i < DataList1.Items.Count ; i++)
{
DataList1.Items.Controls.Clear();
}
}
else
{
for (int i = 0; i < (p-1)*range ; i++)
{
DataList1.Items.Controls.Clear();
}

for (int i = range*(p) ; i < DataList1.Items.Count; i++)
{
DataList1.Items.Controls.Clear();
}

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,113
Latest member
Vinay KumarNevatia
Top