开发者

problem in Retrieving rich text box sharepoint

I need to retrieve values from a rich text box from a list.My code till now is this..

        ArrayList arCategory=new ArrayList();               
        SPList myList = myWeb.Lists["PList"]; 
        SPQuery myQuery = new SPQuery();
        myQuery.Query = "<OrderBy><FieldRef Name='ProgramID' Ascending="False"/></OrderBy>;

            SPListItemCollection myItemCol = myList.GetItems(myQuery);

            foreach (SPListItem myItem in myItemCol)
            {                   
                string strCatTxt = (string)myItem["Category"];-->

//Category is the mu开发者_如何学JAVAltiline rich text column

              arCategory.Add(strCatTxt);
            }

           for (int j = 0; j < arCategory.Count; j++)
          {
          Label lblCategory = new Label();
          lblCategory.Text=arCategory[j].Tostring(); ---->Getting exception
          }


The problem is not SharePoint here. In your code, you have lblCategory.Text=arCategory[j].Tostring();

If arCategory[j] is null, you get an exception when you call ToString() on it.

So basically you can fix it like this:

for (int j = 0; j < arCategory.Count; j++) {
  if (arCategory[j]!=null){
    Label lblCategory = new Label();
    lblCategory.Text=arCategory[j].Tostring(); ---->Getting exception
  }
}

EDIT: Or, of course, you could add a <Where>... element in your query and read only values from the items which have Category different from null. This will also make your query execute faster!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜