Showing posts with label output. Show all posts
Showing posts with label output. Show all posts

Saturday, March 31, 2012

trim a URL link through datagrid

Hi,

Is there anyway I can trim this URL?

The Output is something like this:http://www.test.com/default.aspx?siteid=1&pagetitle=this_is_a_test and I want to get rid of everything past "?" so it just showshttp://www.test.com/default.aspx

This is the code i am using to get the URL through a datagrid in C#: 'Navigate='<%# Databinder.Eval(Container.DataItem, "LinkPath") %>' How can I trim this URL in the backend?

Thanks for anyone that can help me out.

Hi

Hope this helps

//Create a method calledstring GetTrimmedURL(string CompleteURL){ string TrimmedURL = String.Empty; string str = CompleteURL;int intIndexOfchar = str.IndexOf("?"); TrimmedURL = str.substring(intIndexOfchar, (str.Length() - intIndexOfchar));return TrimmedURL;}

Call this method at the place where you are doing the data binding. Say something like

'Navigate='<%# GetTrimmedURL(Databinder.Eval(Container.DataItem, "LinkPath")) %>'

Please note that this trims from the first instance of question mark though.

Hope this helps

Note: Pls watch out for small syntactical errors. Did this on a notepad.

VJ


Hi

You can do the following to strip the querystring off the URL:

Uri linkPath =new Uri(YOUROBJECTHERE.LinkPath);string newLinkPath = linkPath.Scheme + "://" + linkPath.Host + linkPath.AbsolutePath;

You could either do this is in the class you are databinding to, or perhaps in an OnItemDataBound event handler on your DataGrid, depending on your preference.

Hope this helps.

Seb

Trimming Spaces

I'm having a problem with the ff. Front Office code. My desired output is to get the first letter of the First Name and all of the Last Name to the mailto. However, I always get spaces after the lastname even if I trimmed it down already.

Ex.
Name = Robert Garcia
Desired Output = RGarcia@dotnet.itags.org.emailtest.com
Actual Output = RGarcia @dotnet.itags.org.emailtest.com

*** CODE ***
href="mailto:<%=left(FP_FieldLink(fp_rs,"Firstname"),1) & TRIM(FP_FieldLink(fp_rs,"Lastname"))%>@dotnet.itags.org.emailtest.com">
*** CODE ***

Any inputs would be appreciated.What is FP_FieldLink?
Maybe its a non visible character which you need to get rid of? Try to get the ascii value of the white space and use this ascii value in the replace method. Do a response.write with:

asc(left(yourvar, spaceposition))

Thursday, March 22, 2012

Trouble with Request.Form- output is blank

Hey all,

I'm very much new to ASP and ASP.net, and I'm having difficulties in figuring out to get ASP.net to properly output the value of a form field in a vb script. The field in particular is one that contains a two-letter abbreviation of a state (E.g. if the visitor selected California, the value of the field would be CA). This normally works fine, but when a visitor selects Indiana, that's where ASP.net returns nothing. I can see that ASP.net recognizes IN as VB code, I'm just not sure how to force it to just print IN.

Here's a snippet of the code:


obj.OrigZipPostal = Request.Form("vendorpostal" & i)
obj.OrigStateProvince = Request.Form("vendorstate" & i)

Thanks for helping a newbie out :D

You need to convince vb.net that you are using a string and not a command, you could try CStr() or use quotes...

Hope that this helps.


Use

obj.OrigStateProvince = CStr(Request.Form("vendorstate" & i))

Thanks


Thanks guys, that solved the problem.