select ddl item based on the url - c#

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

Related

Find a work item using an attached hyperlink

I create work items through the TFS api.
var type = project.WorkItemTypes["Bug"];
var workItem = new WorkItem(type)
{
History = "Created by OneTrueError incident #" + dto.OneTrueErrorIncidentId,
Title = dto.Title,
Description = dto.StackTrace,
};
workItem.Fields["Activity"].Value = dto.Activity;
workItem.Fields["Repro Steps"].Value = dto.StepsToReproduce;
workItem.Links.Add(new Hyperlink(someBaseUri + "/issue/" + dto.OneTrueErrorIncidentId));
workItem.Save();
At a later point I want to be able to fetch a specific work item by querying on a Hyperlink that I attached when creating the work item.
I can't figure out how to write that query. All examples I've found regarding links are for links to other work items or TFS resources. I have had no luck trying to modify those examples.
So how can I find a specific workitem using WIQL and a specific Hyperlink.Location?
Unfortunately, it's not able to directly use hyperlink url info in WIQL. You could only use Hyperlink Count field which returns the number of hyperlinks that are defined for the work item.
Reference Name=System.HyperLinkCount, Data type=Integer
As a workaround you may have to get a list of worktiems with links and go through all returned info to match the url that your attached when creating the work item. Then get the work item.

Selenium to select and click on correct link

Please dont get bored of answering my questions continuously for the same type of data. I am using Selenium and c# for my application. Here also I have a web page with contents like this:
Description App Name Information
Some Desc1 App1 Some Info
Some Desc2 App2 Some Info
Some Desc3 App2 Some Info
Some Desc4 App3 Some Info
Some Desc5 App4 Some Info
As said in my earlier questions, in my application the user enters an appname of his own choice. And that appname I have stored it in a variable. What I need to do is that, I want selenium to search for that appname and it must click on corresponding Description of that.
An example scenario is: If the user enters APP2, then selenium should search for the appname "App2" and after that first it should click on Some Desc2 and then after some time it should click on some Desc3. For Your Information, all the "some Desc's" links have no classname, no id, and have same tagname.
Try this:
driver.findElement(By.id("table-id"));
List<WebElement> rows = table.findElements(By.tagName("tr"));
for (WebElement row : rows) {
List<WebElemebt> cells = row.findElements(By.tagName("td"));
if (cells[1].getText().equals("AppNameYouWantToFind")) {
cells[0].click();
}
}
I hope you understand what's going on here but I'll describe it anyway.
First, you find the table with the relevant data. Then you find each of the rows within that table, forming a list of webelemebts. For each of those rows you then create a list of all the cells. Due to your table layout you know that the App Name data is located in the second cell in your list, 'index=[1]'. So make a comparison there for the search term you want - if it matches click the proceeding cell.
That's in Java I'm afraid, you'll have to convert that to c#.
UPDATED ANSWER
driver.findElement(By.id("table-id"));
List<WebElement> rows = table.findElements(By.tagName("tr")); //get list to know how many times to loop
for (int i=0; i<rows.length(); i++) {
rows = table.findElements(By.tagName("tr")); //this is required as you'll be 'refreshing' the list to avoid 'stale element exceptions' after going back
List<WebElemebt> cells = rows[i].findElements(By.tagName("td"));
if (cells[1].getText().equals("AppNameYouWantToFind")) {
cells[0].click();
//do what you need to do on the new page
driver.navigate.back();
}
}

Creating a new form - Sharepoint

So I have the code as such:
private void newAddFormForMembers(SPList list, SPWeb web)
{
list = web.Lists["MemberRecords"];
string url = string.Format("_layouts/createform.apsx", web.ServerRelativeUrl, list.RootFolder.Url);
var form = web.GetFile(url);
if (form != null)
{
list.DefaultNewFormUrl = url;
list.Update();
}
}
I have used SharePoint 2010 designer to go and grab the existing html for the creatform form when adding items to a particular list. I added in two new fields, first and last name. The list contains a member name, I removed this field from the create form because:
When I hit submit to add the item to the list, first and last name need to format them selves into "lastname, first name". Now I could submit the form back to my self - How do I do that? - and then do my string manipulation How do i get the values form a field? - and then push the information to the list How do I do that? but then I have anew issue
Edit will look the exact same as add, first and last name fields, how would I take the information from the list and populate the new edit form, particularly first and last name fields, keeping in mind that in the list they are in the format of "lastname, firstname"?
This is all being done programatically
Instead of change html newForm for the list try to write an Event Receiver
Instead of delete field from the newForm try to hide columns (You can do that programmatically or using external tool such as Sharepoint Manager
Adding fields to the new/edit form and grab value on postback event I think is not simple/possible (via javascript you can access onPreSave where you can manipulate item values before postback, here you can write some jscript for save values into field but on edit is hard to split values).
You can: create two column on your list FirstName and LastName, plus a third field FullName (hidden for new/edit form) and with an EH on Added/Updated you can write FullName = LastName + ", " + FirstName or without EH you can create a calculated Field.

Switchin/reversing a string in a SharePoint list item

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());

Dropdown with image and text together in Asp.net 3.5 and jquery

I've been given a task to make a dynamic drop down which takes it's data[image and value id] from table. I am wondering if any of you came across this scenario or if any one can help me out in this I need help in concept and coding. Definitely any help is appreciated.
I see the example in jquery here is the link:
http://www.marghoobsuleman.com/jquery-image-dropdown
something like this but data is coming from table.
If you use the plugin that you found in the link, then basically what you will want to do is create the dropdown dynamically based on the table content. Without having more details of how your table is structured I can't give you exact details, but something like this should get you close (I'm going to assume there is a drop-down element already on the page somewhere called "select", and your table is called "table" with the image in field 0, and the text in field 1) Note: This hasn't really been tested.
var options = "";
$("#table tr").each(function() {
var imagePath = $(this).find("td:eq(0) img").attr("src");
var title = $(this).find("td:eq(1)").text();
options += '<option value="'+title+'" title="'+imagePath+'">'+title+'</option>';
});
$("#select").html(options);

Categories