shanthi_joseph
asked on
String append does not work
System.Text.StringBuilder sb = new System.Text.StringBuilder( );
sb.Append("javascript:open jobdetails ('employer _info.aspx ?SupplierI d=");
sb.Append(GlobalFunctions. Encrypt(em ployerId.T oString()) );
sb.Append("&prth_act=info" );
if (!string.IsNullOrEmpty(ref erenceNumb er))
{
sb.Append("&ref_num=");
sb.Append(referenceNumber) ;
}
sb.Append("')");
The last append does not work. I get the following output:
javascript:openjobdetails( 'employer_ info.aspx? SupplierId =ODM=&prth _act=info& ref_num=PM /12
sb.Append("javascript:open
sb.Append(GlobalFunctions.
sb.Append("&prth_act=info"
if (!string.IsNullOrEmpty(ref
{
sb.Append("&ref_num=");
sb.Append(referenceNumber)
}
sb.Append("')");
The last append does not work. I get the following output:
javascript:openjobdetails(
it has to work, you must have that line after using sb to get the output.
Is there anything between the last } and the last sb.Append line? I just whipped up a quick example and got the correct output.
Produces the the following output:
-saige-
using System;
using System.Text;
public class Program
{
public static void Main()
{
string empID = "ODM";
string refNum = "PM/12";
StringBuilder sb = new StringBuilder();
sb.Append("javascript:openjobdetails('employer_info.aspx?SupplierId=");
sb.Append(empID);
sb.Append("&prth_act=info");
if (!string.IsNullOrEmpty(refNum))
{
sb.Append("&ref_num=");
sb.Append(refNum);
}
sb.Append("')");
Console.WriteLine(sb.ToString());
// Wait for user input to close the program.
Console.ReadLine();
}
}
Produces the the following output:
-saige-
ASKER
public string GetCompanyLogo(object objEmployerId, object objReferenceNumber)
{
string strCompanyLogo = string.Empty;
string referenceNumber = string.Empty;
if (objReferenceNumber != null)
{
referenceNumber = Convert.ToString(objReferenceNumber);
}
if (objEmployerId != null)
{
int employerId = Convert.ToInt32(objEmployerId);
List<Users> users = Users_List.SelectByID(employerId);
if (users.Count > 0)
{
String thumbCompanyLogo = users[0].ThumbCompanyLogo;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("javascript:openjobdetails('employer_info.aspx?SupplierId=");
sb.Append(GlobalFunctions.Encrypt(employerId.ToString()));
sb.Append("&prth_act=info");
if (!string.IsNullOrEmpty(referenceNumber))
{
sb.Append("&ref_num=");
sb.Append(referenceNumber);
}
sb.Append("')");
string href = sb.ToString();
string innerHtml = "<img src='images/No-logo.jpg' border='0' align='absmiddle' width='70px' title='View Details'/>";
if (!string.IsNullOrEmpty(thumbCompanyLogo) && File.Exists(Server.MapPath("uploadedfiles/" + thumbCompanyLogo)))
{
innerHtml = "<img src=\"uploadedfiles/" + thumbCompanyLogo + "\" border=\"0\" align=\"absmiddle\" width=\"70px\" title=\"View Details\"/>";
}
strCompanyLogo = "<a href=" + href + ">" + innerHtml + "</a>";
}
}
return strCompanyLogo;
}
and the aspx file is as follows:
<ItemTemplate>
<tr style="font-size: medium">
<td>
<%# GetCompanyLogo(Eval("EmployerID"), Eval("Reference_Number")) %>
In the function, it returns only part of the string.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works perfectly.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for shanthi_joseph's comment #a40427536
for the following reason:
It worked perfectly
Accepted answer: 0 points for shanthi_joseph's comment #a40427536
for the following reason:
It worked perfectly
Looking at the previous comment, I think accepting that comment as the solution was a mistake.