Paging with asp.net menu control
Just pass the total number of records, currently displayed record and menu control.if you want to display like 10 number for paging.If i select page number 15 this will fill the menu from 10 to 20 etc.
i.e.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
12 13 14 15 16 17 18 19 20 21
public void fillmenu(int tot, int value, Menu menu)
{
if (tot > 100)
{
int page_count = 0;
if (tot % 10 == 0)
page_count = tot / 10;
else
page_count = tot / 10 + 1;
if (menu.SelectedValue == "" || menu.SelectedValue == null)
{
menu.Items.Clear();
for (int i = 1; i <= 10; i++)
{
string text = "";
if (i == value)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
MenuItem mi1 = new MenuItem(text, i.ToString());
menu.Items.Add(mi1);
}
menu.Items.Add(new MenuItem(".....", ""));
menu.Items[10].Selectable = false;
MenuItem mi3 = new MenuItem((page_count).ToString(), (page_count).ToString());
menu.Items.Add(mi3);
}
else
{
if (Convert.ToInt32(menu.SelectedValue) <= 5)
{
}
else if (value > page_count - 5)
{
menu.Items.Clear();
for (int i = page_count - 10; i <= page_count; i++)
{
string text = "";
if (value == i)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
}
}
else
{
int sel = Convert.ToInt32(menu.SelectedValue);
menu.Items.Clear();
for (int i = sel - 4; i <= sel + 5; i++)
{
string text = "";
if (value == i)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
}
menu.Items.Add(new MenuItem(".....", ""));
menu.Items[10].Selectable = false;
MenuItem mi2 = new MenuItem((page_count).ToString(), (page_count).ToString());
menu.Items.Add(mi2);
}
}
}
else
{
menu.Items.Clear();
for (int i = 1; i <= tot / 10 + 1; i++)
{
string text = "";
if (i == value)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
}
}
}
No comments:
Post a Comment