Reading a ListView on pageload

Last post 11-23-2008 9:53 PM by docluv. 1 replies.

Sort Posts:

  • Reading a ListView on pageload

    11-23-2008, 7:08 PM
    • Member
      22 point Member
    • Dango23
    • Member since 08-07-2004, 1:16 PM
    • Posts 37

    Hi,

     I have a page with ListView data control that is reading SQL Server Stored procedure and I have a good templete for displaying the selected data I get back.

    Now, I am trying really hard to read my ListView items. Every item in my ListView has a "UserId" and I need on PageLoad() to read all the UserId on page.

    How can I do that? I had real trouble to do that. I tried all kinds of foreach loops but nothing worked. Can you help?

    What is the correct way to read all my data in my items in  ListView with C# ?

    ======================================================================== 

    protected void ItemDataBound(object sender, ListViewItemEventArgs e)
        {
          if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem item = (ListViewDataItem)e.Item;
                DataRowView vw = (DataRowView)item.DataItem;
                if (vw["UserName"].ToString().Equals("Something"))
                {
                    // do something
                }
            }

    }

    ==============================================================

    Well, I did found code that worked for me in this forum - BUT I see it reads only the items that are display in one page because I use PAGING.

    Can I check all my list items although I have paging , because now if I have 5 items in on page, it checks only this 5 items and not the 5 items at the next page. Can I do something in order to check ALL items in all Pages?

    "Try not to become a man of success but rather a man of value." / Albert Einstein
    Filed under:
  • Re: Reading a ListView on pageload

    11-23-2008, 9:53 PM
    Answer
    • Star
      12,627 point Star
    • docluv
    • Member since 06-29-2002, 7:16 PM
    • Willow Spring NC
    • Posts 1,996
    • ASPInsiders
      TrustedFriends-MVPs

    You would need to do that in your stored procedure. I guess I don't understand why you would care about items you are not displaying, unless you want to repeat you code every time the page is loaded. If that were the case, then I would setup some sort of background process to handle that for me so your content can be sent to the browser while that is processing.

Page 1 of 1 (2 items)