Evaluate SPListItem field values using debugger - visual-studio

How do I evaluate SPListItem field values using VS debugger? Best I get is only a list of Field names, but not values.

Try this:
oListItem["Assigned To"]
where oListItem is the name of your Item and "Assigned To" is the name of the field.

Related

How to get attribute value of mutiple selection in the Owebia shipping method

How to get attribute value of multiple selection in the Owebia shipping method?
My Owebia code below:
{count items where array_match_any(product.attribute.**shipping_restriction**.**value**', array('AU','NZ','AU,NZ'))}
But,I can't get the attribute value,I only can get the id num of attribute,
shipping_restriction is my custom attribute,which has a multiple selected menu.
It just return the index num,not 'NZ' or 'AU',it just return the index num,not 'NZ' or 'AU'
If I have changed the multiple selected menu into single selection,it could get right value. Like 'NZ' or 'AU',and not index num.
You can try by using following syntax to get value.
product.attribute.*.value
Where * is attribute placeholder.
Reference: http://www.owebia.com/os2/en/doc#formulas_variables_product

"Correct" way to separate numeric User ID from "id;#name" value in SP2010 Person or Group list field?

This is for SharePoint 2010, and I'm using Visual Studio 2010. I have a list. In the list there is a "Person or Group" field, who's members are pulled from a group. So, somebody adds an item from the list and picks a name displayed in my "Reviewer" field. No problem.
Over in VS2010 (this is for a workflow, fwiw), I have this...
SPListItem listItem = spList.GetItemById(listItemId);
String reviewerUsername = listItem["Reviewer"].ToString();
But if I try to use that reviewerUsername value to populate an SPUser, it fails, and various other stabs at it also fail.
Using the debugger, I can see the value of reviewerUsername = "23;#Doe, John"
My look at the SPUser object shows I could use GetUserById() and use that "23" in the "23;#Doe, John" to get the user, and a test of this method works.
So my question, to stay on track with the subject is, is there a specific method (as in function) I should use to extract just the numeric ID from that "23;#Doe, John" string?
just use normal string method Split to split your string on ";#" and get the first part which is the ID
ex:
string reviewerID = reviewerUsername.Split(new string[] { ";#" }, StringSplitOptions.None)[0];

Setting a default selected value in DropDownList in MVC3

In MVC3 I have this code at my controller. It retrieves a List of IDs\Names from Installation table and creates a ViewBag
var vs = dba.Installation.OrderBy(q => q.InstName).ToList();
ViewBag.Vessels = new SelectList(vs, "InstId", "InstName");
Now, at my view. I want to render the list in a dropdown list. I used the Html helper that works fine...
#Html.DropDownList("InstId",(SelectList)ViewBag.Vessels, "- Select one -")
I need to set first item in the ViewBag List as a default selected value, instead of "- Select one -" text.
How can I do it?
Thanks in advance!
There's an overload for the SelectList constructor that takes 4 arguments. The last of which is the default selected object. E.g:
ViewBag.Vessels = new SelectList(vs, "InstId", "InstName", selectedValue);
Where selectedValue is an object of whatever type is in your list.
I need to set first item in the ViewBag List as a default selected
value, instead of "- Select one -" text.
Then you need to select the first item in your list (vs) and get it's id and use it as the selecedValue in the SelectList:
ViewBag.Vessels = new SelectList(vs, "InstId", "InstName",
vs.FirstOrDefault().InstId);
You can also create an Helper class for Dropdownlist
It will have a method to set the text as by default text for every dropdownlist in you solution

Dynamic Linq - no property or field exists in type 'datarow'

I am using Northwind Customers Table where I fill the dataset and get the datatable.
I am trying to use dynamic linq and want to select columnName dynamically
var qry = MyDataTable.AsEnumerable().AsQueryable().Select("new(Country)");
Right now I have hard coded country but even then I get this error
No property or field 'Country' exists in type 'datarow'
I would like to eventually change this query to take the column name dynamically.
Please help!!! thanks.
The important hint is here (in bold):
No property or field 'Country' exists
in type 'datarow'
The extension method AsEnumerable of the DataTable class returns an IEnumerable<T> where T has the type DataRow. Now the Select method of Dynamic LINQ wants to work with this type DataRow which hasn't a property Country of course.
You could try this instead:
var qry = MyDataTable.AsEnumerable().AsQueryable()
.Select("new(it[\"Country\"] as CountryAlias)");
it now represents a variable of type DataRow and you can use methods of this type and perhaps also the indexer in my example above. (Dynamic LINQ supports accessing array elements by an integer index, but I am not sure though if accessing an indexer with a string key will work.)
I've used Slauma's answer and it worked. In addition i was doing OrderBy with dynamic linq maybe this will help to someone. I'll just drop the code here.
string dynamicLinqText = $"it[\"{sortColumnName}\"] {sortDirection}"; //it["PERSON_NAME"] asc
result = result.AsEnumerable().OrderBy(dynamicLinqText).CopyToDataTable();

Linq Object as ComboBox DataSource

I have a ComboBox being bind to LINQ object as below.
Dim LearnTypeList = context.LearnTypes.OrderBy(Function(a) a.LearnType).ToList()
dlLearnedAbout.DataSource = LearnTypeList
dlLearnedAbout.DisplayMember = "LearnType"
dlLearnedAbout.ValueMember = "LearnType"
I am not able to use Index of Items to find Item with matching text as below .
MessageBox.Show(dlLearnedAbout.Items.IndexOf("Website"))
This always returns -1 even if its there inside the table and dropdown.Is it because the Item bound to the Dropdown is of type "LearnTypes ?
IndexOf("Website") is looking through the list for an item of type String. your list doesn't contain strings though - it contains objects of whatever type you have in context.LearnTypes. that's why you are getting -1 (aka item not found)

Resources