Link to home
Start Free TrialLog in
Avatar of shanthi_joseph
shanthi_joseph

asked on

String append does not work

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

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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.

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

Open in new window


Produces the the following output:User generated image
-saige-
Avatar of shanthi_joseph
shanthi_joseph

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;
    }

Open in new window



and the aspx file is as follows:

 <ItemTemplate>
        <tr style="font-size: medium">
            <td>
                <%# GetCompanyLogo(Eval("EmployerID"), Eval("Reference_Number")) %>

Open in new window

In the function, it returns only part of the string.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This works perfectly.
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
Looking at the previous comment, I think accepting that comment as the solution was a mistake.