Ressourcen für IT-Professionals > Forenhomepage > SharePoint - Development and Programming > Accessing list item shows null, but items are there in discussion board
Stellen Sie eine FrageStellen Sie eine Frage
 

FrageAccessing list item shows null, but items are there in discussion board

  • Freitag, 3. Juli 2009 14:10arun_in TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    Hi All,

    I am trying to itrate DISCUSSION BOARD items(threads),
    and List.ItemCount shows 2 items, but when i try to access
    items, it shows listItem null, and debugger comes out of loop

         SPList list=web.Lists["DBoard"];
                int i = list.ItemCount;
                foreach (SPListItem listItem in list.Items)
                {


                }

    I am not able to find, what i am doing wrong here.


    arun singh

Alle Antworten

  • Freitag, 3. Juli 2009 14:28Naresh kilaru [MCTS] TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hope this may helps you.

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/afe07483-6aec-424a-9434-c8e8b963e55c
  • Freitag, 3. Juli 2009 14:44SP RAJ TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Enthält Code
    Arun, you can try the below code

    SPList list = myweb.Lists["DBoard"];
                SPQuery myquery = new SPQuery();
                myquery.Query = "<Query><OrderBy><FieldRef Name='Subject'/></OrderBy></Query>";
                SPListItemCollection myitemcol = list.GetItems(myquery);
                DropDownList1.Items.Clear();
                DropDownList1.AppendDataBoundItems = true;
                DropDownList1.Items.Add(new ListItem("Select...", ""));
                foreach (SPListItem listitem in myitemcol)
                {
                    DropDownList1.Items.Add(new ListItem(listitem["Subject"].ToString()));
                }
    



  • Freitag, 3. Juli 2009 14:59arun_in TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    Hi RAJ,

    Actually i am using SPEmailEventReciever handler, inside that i placed ur code...

    But as usual it is coming from loop 

    foreach
    (SPListItem listitem in myitemcol)
                {
                    DropDownList1.Items.Add(new ListItem(listitem["Subject"].ToString()));
                }

    as it is not getting item in the collection.
    I dont know what is happening here.
    arun singh