LINQ and ListView problem

Discussion in 'ASP .Net' started by shapper, Dec 13, 2007.

  1. shapper

    shapper Guest

    Hello,

    I have a ListView where I use LINQ for data, for example, selecting,
    and deleting.
    In the ListView item template I added a DataPager.

    When I click, for example, "Next Page" or a page number in the
    DataPager something strange happens:
    It always takes me 2 clicks for the action to be taken.

    The only thing that solves this is to move the code I have in my
    ListView Load event to the ListView PreRender event.

    Please, does anyone has any idea what I am doing wrong?

    Here is my ListView code:

    Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
    EventArgs) Handles lvTags.Init
    lvTags.DataKeyNames = New String() {"TagID"}
    lvTags.ID = "lvTags"
    lvTags.ItemTemplate = New
    TagsTemplate(TemplateType.ItemTemplate)
    lvTags.LayoutTemplate = New
    TagsTemplate(TemplateType.LayoutTemplate)
    End Sub
    Private Sub lvTags_Load(ByVal sender As Object, ByVal e As
    EventArgs) Handles lvTags.Load
    Dim database As New CodeDataContext
    Dim tags = From t In database.Tags Select t.TagID, t.Text
    lvTags.DataSource = tags
    lvTags.DataBind()
    End Sub ' lvTags_Load

    And my DataPager code which I add inside the ListView ItemTemplate
    implementation is:

    Private Sub dpTags_Init(ByVal sender As Object, ByVal e As
    EventArgs)

    Dim dpTags As DataPager = CType(sender, DataPager)

    Dim field As New NextPreviousPagerField
    field.FirstPageText = "<<"
    field.PreviousPageText = "<"
    field.NextPageText = ">"
    field.LastPageText = ">>"

    dpTags.ID = "dpTags"
    dpTags.PageSize = 8
    dpTags.Fields.Add(field)

    End Sub ' dpTags_Init

    Thanks,
    Miguel
    shapper, Dec 13, 2007
    #1
    1. Advertising

  2. shapper

    David Wier Guest

    Try moving the Datapager outside the Listview ItemTemplate. You should be
    able to put it anywhere on the page, and set the PagedControlID to your
    ListView

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "shapper" <> wrote in message
    news:...
    > Hello,
    >
    > I have a ListView where I use LINQ for data, for example, selecting,
    > and deleting.
    > In the ListView item template I added a DataPager.
    >
    > When I click, for example, "Next Page" or a page number in the
    > DataPager something strange happens:
    > It always takes me 2 clicks for the action to be taken.
    >
    > The only thing that solves this is to move the code I have in my
    > ListView Load event to the ListView PreRender event.
    >
    > Please, does anyone has any idea what I am doing wrong?
    >
    > Here is my ListView code:
    >
    > Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
    > EventArgs) Handles lvTags.Init
    > lvTags.DataKeyNames = New String() {"TagID"}
    > lvTags.ID = "lvTags"
    > lvTags.ItemTemplate = New
    > TagsTemplate(TemplateType.ItemTemplate)
    > lvTags.LayoutTemplate = New
    > TagsTemplate(TemplateType.LayoutTemplate)
    > End Sub
    > Private Sub lvTags_Load(ByVal sender As Object, ByVal e As
    > EventArgs) Handles lvTags.Load
    > Dim database As New CodeDataContext
    > Dim tags = From t In database.Tags Select t.TagID, t.Text
    > lvTags.DataSource = tags
    > lvTags.DataBind()
    > End Sub ' lvTags_Load
    >
    > And my DataPager code which I add inside the ListView ItemTemplate
    > implementation is:
    >
    > Private Sub dpTags_Init(ByVal sender As Object, ByVal e As
    > EventArgs)
    >
    > Dim dpTags As DataPager = CType(sender, DataPager)
    >
    > Dim field As New NextPreviousPagerField
    > field.FirstPageText = "<<"
    > field.PreviousPageText = "<"
    > field.NextPageText = ">"
    > field.LastPageText = ">>"
    >
    > dpTags.ID = "dpTags"
    > dpTags.PageSize = 8
    > dpTags.Fields.Add(field)
    >
    > End Sub ' dpTags_Init
    >
    > Thanks,
    > Miguel
    David Wier, Dec 13, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmus
    Replies:
    0
    Views:
    454
    Rasmus
    Dec 12, 2007
  2. Mike N.
    Replies:
    0
    Views:
    487
    Mike N.
    Jul 31, 2008
  3. Mike N.
    Replies:
    0
    Views:
    630
    Mike N.
    Jul 31, 2008
  4. George

    Linq or not Linq

    George, Nov 4, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    343
    Mike Gleason jr Couturier
    Nov 5, 2008
  5. .
    Replies:
    0
    Views:
    704
Loading...

Share This Page