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!
精彩评论