Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Linq's Got Issues

Linq's Got Issues

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinq
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tarik Guney
    wrote on last edited by
    #1

    Hey everyone, I was trying to achieve custom data paging by using LINQ but LINQ has got some issues. Ok let me introduce what i've done and got back. There are 2 dropdownlists and listbox on my page. one of dropdownlists is for Page Number and the other is for Page size and the results show in ListBox. Page number is changing according to selected size at dropdownlist which is for page size. and the related code is here : private void FindPageTotalNumber() { ddPageIndex.Items.Clear(); UsersDataContext tu = new UsersDataContext(); var allusersNumbers = from users in tu.Kullanicis select new { users.KullaniciID }; int selectedPageSize = Convert.ToInt32(ddPageSize.SelectedItem.Text); int count = allusersNumbers.Count(); int totalPageSize = 0; if (count % selectedPageSize == 0) { totalPageSize = count / selectedPageSize; } else { totalPageSize = (count / selectedPageSize) + 1; } for (int i = 1; i <= totalPageSize; i++) { ddPageIndex.Items.Add(i.ToString()); } } Now here is the DataBind Code to bind related data to ListBox after changing page number or page size : private void BindDataToUsersListBox() { UsersDataContext u = new UsersDataContext(); var users = from au in u.Kullanicis select new { au.KullaniciAdi, au.KullaniciID }; int pageIndex = Convert.ToInt32(ddPageIndex.SelectedItem.Text); int pageSize= Convert.ToInt32(ddPageSize.SelectedItem.Text); lbKullanicilar.DataSource = users.Skip((Convert.ToInt32(pageIndex)-1)*pageSize).Take(pageSize); lbKullanicilar.DataBind(); } The other Stuff : protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { FindPageTotalNumber(); BindDataToUsersListBox(); } } protected void ddPageSize_SelectedIndexChanged(object sender, EventArgs e) { FindPageTotalNumber(); BindDataToUsersListBox(); } protected void ddPageIndex_SelectedIndexChanged(object sender, EventArgs e) { BindDataToUsersListBox(); } Ok now when I select page size 1, naturally page index is increasing and should show data one by

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups