Switchin/reversing a string in a SharePoint list item - c#

I have a question on whether it would be possible to switch/reverse the ordering of string values in a SharePoint list item in code behind to then display the result of the processed string.
So currently to illustrate this I have an "Employees" SharePoint list with the following columns:
Title
Position
Now the title column has the following values:
Ted Baker
Joe Pierce
I have a simple web part that displays the list item values, but for the "Title" field rather than displaying "Ted Baker", I want it to be displayed "Baker Ted" so essentially displaying the last string value first.
Is this possible to do and if so what would be the best way to do it?
Thanks in advance

string name = "Ted Baker";
string newname = String.Join(" ",name.Split(' ').Reverse());

Related

Make a list understand which item is selected C#

I'm stuck.
I have 2 different listviews, the listview1 contains name, and the listview2 are showing the episodes to the name i selected in listview1.
The problem is that i want to have a description in a label of the specific episode i select in the listview2.
Right now i have all episodes in order in the listview2, and just for testing i have made a listview3 who shows all the descriptions in a list.
i pick out the information from and i use
To get the descriptions.
But the problem is that i dont know how to connect the right episode to the right description. Have someone done something similiar before?
Right now i just loop trough the list and make it appear inte the listview3, but its not correct.
To get the episodes from the url to the list i use
Iterate once through your items and update both lists.
foreach (SyndicationItem episode in feed.Items)
{
var episodeName = episode.Title.Text;
var episodeDesc = episode.Summary.Text;
podcastEpisodes.Add(episodeName);
episodeDescription.Add(episodeDesc);
}
To set the selected item in a listview, you can set its selected/focus state.
Can you simply do this:
lvEpisode.Where(x=> x.Name == NameListView.SelectedItem).Select(x=>x.Name).FirstOrDefault();
This assumes you have a class of item containing Name.
(Typing through mobile, this maynot compile):
Is it possible to convert your episode description from a list to a dictionary? The key would be the episode and the value would be the description. When user selects the episode then you just need to index the dictionary to get the description?
since you are getting a xml data, try parsing as a JSON and the information will likely structured. so the index you use for your episodes should also be used to index the description. so a JSON like
movies={name: "Walking Dead" ,
category: "Horror",
episode:"episode1",
description:"walkers rise again"};
so you can now get movies["episode"]; and movies["description"] easily.
They are online parsers you can put in xml and convert to JSON and also packages for c# too i believe, but put the xml HERE and see how the structure changes.

C# how to match textbox string linq

I'm having trouble matching textboxes using linq.
I have to populate a textbox with a collection that I converted from an array.
The conversion looks like this.
List<string> animalList = new List<string>(animals);
The list contains items such as "Dog", "Cat", "Snake", "Rat", "Mouse", "Duck"
I can populate the first textbox (there are 3 textboxes, one for the collection, one for a word to be input, and one to display whether or not the input word matches the collection).
I don't know much about Linq. Please help point me in the right direction. I've looked all over online, and I can't find an example for something that should be as simple as matching 2 textboxes using Linq.
Should be as simple as textbox1.Text == textbox2.Text
I'm not sure Linq is the way you want to go here. List<T> has a contains() method that should do what you want. Where is the Linq requirement coming from?
Also, I think you mean a Listbox for the collection (as they're designed to hold multiple items), a textbox for entering new values and then a textbox (or label) to display the result after you test the entered value against the contents of the collection, right?
In your event handler you'll want to use a statement like this:
animalList.SingleOrDefault(a => a == textbox1.Text);
That assumes that the textbox where the name of your new animal is typed into is named textbox1.

select ddl item based on the url

On my contact page (contact.aspx)I have a booking form that contains a drop down list control which is dynamically populated with the names of the available drivers to choose from. What I would like to do is on each drivers individual page e.g driver1.aspx provide a 'book this driver' link which when the user selects it they are taken to the contact page and the drop down list is populated with the drivers name of the page they have just come from.
so for example if i am a user viewing Pauls driver page and i select book this driver i am taken to the contact us page and the ddl list has pre selected paul as the prefered driver
Can this be achieved? If so has and one got any links or advice on how to do it?
Thanks
Paul
thanks for your response, I been busy working on this and have achieved it using the following (not sure its the best approach but its doing what i need)
if you can suggest anything better then please let me know :)
//gets the full url of the referal page e.g http://mysite.co.uk/our-drivers/joe-bloggs.aspx
string refererPage = Request.UrlReferrer.ToString();
//splits the referer url to get the latter part containing the name e.g joe-bloggs.aspx
string url = refererPage.Split('/').Last();
//splits the url to get the first part of the url e.g joe-bloggs
string url2 = url.Split('.').First();
// Take the value of url2 replace the hyphen with a space e.g Joe Bloggs then loop through
// the items in the DDL and if there is an item that matches make it the selected item
foreach (ListItem item in ddlPreferedDriver.Items)
{
if (url2.ToLower().Replace("-", " ").Contains(item.Text.ToLower()))
{
item.Selected = true;
}
}
cheers Paul

C# SubItems Issue

I'm a student learning C#, with previous experiences with VB. I'm trying to use a list view to display three pieces of information in three separate columns. The Item is a decimal (Object = 3.50m), and the subItems are the quantity and a price. I have managed to get the first two columns showing the data with:-
var item = lsvstarter.Items.Add(cmbStarter.Text);
item.SubItems.Add(cmbStrQuantity.Text);
The third column should show the worth of the item multiplied by the quantity, so it would be
1st Column "3.50"
2nd Column "3"
3rd Column (3.50 * 3) "10.5"
But the method I used for the first subitem will not work for the variable that should be displayed by the third column. This being
item.SubItems.Add(Startertotal);
The ListView includes 3 columns. I had this program working on VB since the scenario is the same but using translators didn't work successfully. All of the objects in the Design view are the same.
Also the calculation for the "Startertotal" variable has already been calculated in a loop beforehand. Does anyone know what I'm doing wrong and the fix?
MSDN: SubItems.Add takes either a string or a SubItem as its first parameter.
So you need to change the numeric value to a string in one way or another:
item.SubItems.Add(Startertotal + " ");
item.SubItems.Add(Startertotal + "");
item.SubItems.Add(Startertotal.ToString());
item.SubItems.Add(Startertotal.ToString("###0,00"));
item.SubItems.Add(String.Format("Sum: {0} ", Startertotal));
or whatever formatting you want..

Programmatically Checking DevExpress CheckedComboBoxEdit Items

I have a CheckedComboBoxEdit that's bound to a TableAdapter that populates it with a list of items.
I have a separate query that returns a dataset that lists the items that need to be checked.
I need to iterate through the CheckedComboBoxEdit items to check them as needed.
How can I make the CheckedComboBoxEdit reflect the data from the query which returns a list of items that need to be checked?
I'm using C# in Visual Studio 2010 with DevExpress 10.2.9.
Any help on this would be greatly appreciated, and any other solutions to this issue would be great too.
Items state of the CheckedComboBoxEdit tied to its EditValue. You can check items by setting an appropriate editor value: a list of values (each item has the value and display text) delimited with a separator sign. The separator sign is specified via the RepositoryItemCheckedComboBox.SeparatorChar property.
Here is how to
checkedComboBoxEdit1.Properties.SeparatorChar = ';';
// Set the edit value, assuming you have items named "one",and "two"
checkedComboBoxEdit1.SetEditValue("one; two");
Here is the complete example
Short code snippet.
string str = "first;second";
string[] array = str.Split(';');
char separator = checkedComboBoxEdit1.Properties.SeparatorChar;
string result = string.Empty;
foreach (var element in array){
result += element + separator;
}
checkedComboBoxEdit1.SetEditValue(result);

Categories