problem in Retrieving rich text box sharepoint - 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 multiline 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!

Related

String with multiple lines of weblink images. How to display them?

I've got a String full of weblink image (23 links) :
listItem.text = String(item.movieimage);
If I do trace(String(item.movieimage)); the output is :
http://www.thewebsite.nc/Content/images/AFFICHES/xxx_3.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/vaiana.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/tous_scene.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/fits.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/boyfriend.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/sahara2017.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/resident_evil_final.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/raid_dingue.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/passengers2017.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/lego_batman.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/grande_muraille.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/fille_brest.jpg
Know, I've got 9 UILoader on my stage.
So I would like to do
uiloader1.source = item.movieimage[1];
uiloader2.source = item.movieimage[2];
uiloader3.source = item.movieimage[3];
...etc...
How can I do that ?
Thanks
Assuming they're separated by an indent
//Put all the links in an array
var myItems:Array = listItem_txt.text.split("\n");
//You say you only have nine, so only iterate until the 9th
for (var i:int = 0; i < 9; i++)
{
//Also assuming your "uiloader" is a custom class you made with a .source property
this.getChildByName("uiloader" + i).source = myItems[i];
}

Passing ArrayList<CustomObject> along with other parameters to another activity, getting Null from arraylist

Intent intent = getIntent();
Model_Class dataObj = (Model_Class) intent.getSerializableExtra("value");
dataObj.getPrice();
dataObj.get_product_name();
ArrayList<InputListModleClass> _inputList = dataObj.getInputsList();
for (int j = 0; j <_inputList.size(); j++) {
InputListModleClass itemsObj = new InputListModleClass();
Id = itemsObj.getInputId();
Lable = itemsObj.getInputLable();
}
I can get all values from intent, but I am getting null in Id and Lable. How can I resolve this issue.
You are reading from newly created object instead of element from the intent.
InputListModleClass itemsObj = new InputListModleClass();
Instead of this try:
InputListModleClass itemsObj = _inputList.get(j);
and then you should have id and label from intent.

Using datatable to bind sharepoint list title and internal names to dropdownlist

I am trying to get the filed names from 2 sharepoint lists and put them into 2 different dropdownlist on a webpart. However, there were some repeating field names in the dropdownlist. I wonder if my code is correct. or is there any other method to achieve the goal?
DataTable table = new DataTable("table");
DataColumn column;
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "Title";
table.Columns.Add(column);
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "Internal";
table.Columns.Add(column);
DataRow row;
foreach (SPField f in importList.Fields)
{
row = table.NewRow();
row["Title"] = f.Title;
row["Internal"] = f.InternalName;
table.Rows.Add(row);
}
ddlImport.DataSource = table;
ddlImport.DataTextField = "Title";
ddlImport.DataValueField = "Internal";
ddlImport.DataBind();
You may consider Removing hidden field
foreach (SPField f in importList.Fields)
{
if (!f.Hidden)
{
row = table.NewRow();
row["Title"] = f.Title;
row["Internal"] = f.InternalName;
table.Rows.Add(row);
}
}

How to set Spinner selection by value, using CursorAdapter

I have a spinner I'm populating from the database. I want to choose which item from the list is selected by default. I need to find out what item in the list (CursorAdapter) has the value "Default Away" and set that to the selected value.
Spinner away_team_spinner = (Spinner)findViewById(R.id.away_team_spinner);
DatabaseHelper db = new DatabaseHelper(this);
Cursor team_list = db.getTeams(p_game_level);
startManagingCursor(team_list);
String[] team_name = new String[]{colTeamName};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, team_list, team_name, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
away_team_spinner.setAdapter(adapter);
//// HERE IS WHERE MY ERRORS START ////
Log.i("NEW_GAME","Before set arrayadapter");
CursorAdapter adapter_choose = (CursorAdapter)away_team_spinner.getAdapter();
Log.i("NEW_GAME","Before set setSelection");
away_team_spinner.setSelection(adapter_choose.getPosition("Default Away"));
This is the "solution" I found by searching on this web site. However, I cannot use "getPosition" with CursorAdapter object. I tried ArrayAdapter, but then the line after "Before set arrayadapter" comment errors with "android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter". What am I doing wrong? Thanks.
have you thought about running a for loop until you find the position then set the adapter position that way? ill draft up some code then test it, i'm doing something similar
and well this just did the trick, enjoy!
int cpos = 0;
for(int i = 0; i < simpleCursorAdapter.getCount(); i++){
cursor.moveToPosition(i);
String temp = cursor.getString((your column index, an int));
if ( temp.contentEquals(yourString)){
Log.d("TAG", "Found match");
cpos = i;
break;
}
}
spinner.setSelection(cpos);

SubSonic SubSonic.SqlQuery & Dates

Does SubSonic.SqlQuery have a between/and for date ranges? If not, what would be the best way to get a range.
Try something like this:
SqlQuery query = new SqlQuery().From("Table")
.WhereExpression("Column")
.IsBetweenAnd("1/1/2008", "12/31/2008");
DataSet dataSet = query.ExecuteDataSet(); // Or whatever output you need
Another way to query with SubSonic.
TableCollection data = new TableCollection();
Query q = Table.CreateQuery()
.BETWEEN_AND("Column", "1/1/2008", "12/31/2008");
data.LoadAndCloseReader(q.ExecuteReader());
// loop through collection
Combined Northwind answer:
SqlQuery query = new SqlQuery().From("Orders")
.WhereExpression("OrderDate")
.IsBetweenAnd("1996-07-02", "1996-07-08");
DataSet dataSet = query.ExecuteDataSet(); // Or whatever output you need
#region PresentResultsReplaceResponseWriteWithConsole.WriteLineForConsoleApp
DataTable dt = dataSet.Tables[0];
Response.Write("<table>");
foreach ( DataRow dr in dt.Rows )
{
Response.Write("<tr>");
for (int i = 0; i < dt.Columns.Count; i++)
{
Response.Write("<td>");
Response.Write(dr[i].ToString() + " ");
Response.Write("<td>");
} //eof for
Response.Write("</br>");
Response.Write("</tr>");
}
Response.Write("<table>");
#endregion PresentResultsReplaceResponseWriteWithConsole.WriteLineForConsoleApp

Resources