about datalist and access datasource

  • Thread starter Thread starter miladhatam
  • Start date Start date
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
 
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();
}

}
}
 
Back
Top