Help with my custom listbox code please!

I am working on a  custom listbox  and using the code from http://www.codeproject.com/KB/aspnet/CustomListBox.aspx which is great but its done with an array giving the info to the listbox i need it to instead read from a textfile and populate the list box via that and based on a if condition insert the correct image behind each line of text. I got the code for reading from the text file figured out just not sure how to put it in.

How would i change this code around to do that? Thanks!
Here is my code i have it spearated into 2 parts my design source code and my C# code:
 
Design Source Code:
 
<html>
<head>
    <title>untitled</title>
    <link href="MyStyle.css" type="text/css" rel="stylesheet" />
    <script language="javascript">
var selected = null;
 
function setColor(elem, col)
{
	if(elem == selected || elem == null)
		return;
	elem.style.background = col;
	elem.style.cursor='default';
 
}
function select(elem)
{
 
	if(elem == selected || elem == null)
		return;
	else if(selected != null)
	{
	   selected.style.background = "white";
	   selected.style.color = "black";
 
 
	}
	setColor(elem, "blue");
	selected = elem;
	elem.style.color = "white";
 
 
	var val = elem.innerHTML;
    document.getElementById("selVal").value = val;
 
}
 
</script>
</head>
<body bgcolor="#c5dcf6">
    <form id="form_1" runat="server">
        <font color="blue"><font size=+2>List box</font> 
        <br />
        </font> 
        <div style="OVERFLOW: auto; WIDTH: 100px; HEIGHT: 100px">
            <select style="OVERFLOW: hidden; HEIGHT: 100%" size="100" name="ServerList" noscroll="noscroll">
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
                <option value="abcdefghijklmnopqrestuvwxyz">abcdefghijklmnopqrestuvwxyz</option>
            </select>
        </div>
        <br />
        <br />
        <font color="blue" size=+2>Custom list box</font> 
        <br />
        <div style="BORDER-RIGHT: gray thin groove; BORDER-TOP: gray thin groove; OVERFLOW: auto; BORDER-LEFT: gray thin groove; WIDTH: 345px; BORDER-BOTTOM: gray thin groove; HEIGHT: 334px"><% Response.Write(getList());%>
        </div>
        <p>
            <font color="red">Server Side Code</font> 
        </p>
        <p>
            <input id="selVal" type="hidden" runat="server" />
        </p>
        <p>
            See selected value --&gt; ( <asp:Label id="lblInfo" runat="server"></asp:Label>&nbsp;)
            &nbsp;<asp:Button id="cmdOK" onclick="cmdOK_Click" runat="server" text="OK"></asp:Button>
        </p>
        <script language="javascript">
select(document.getElementById("selected"),"blue");
 
</script>
    </form>
</body>
</html>
 
C# code:
 
 private string Render(ArrayList items)
    {
     String HtmlList = String.Empty;
    
    try
        {
            HtmlList = HtmlList + "<TABLE  width=\"100%\" bgColor=\"white\" border=\"0\" cellpadding =\"0\" cellspacing=\"0\" > <TBODY class=\"list\">";
    
            for(int i=0; i<items.Count; i++)
            {
                string[] item = (string[]) items[i];
    
                string imgPath = item[0];
                HtmlList += "<tr>";
                HtmlList += "<td>" ;
                if(imgPath != "")
                    HtmlList += "<img src=\"" + imgPath + "\">"; // add image if item contains it.
                HtmlList += "</td>" ;
    
                HtmlList += "<td onmouseover=\"setColor(this, 'LightGreen');\" onmouseout=\"setColor(this, 'white');\" onclick=\"select(this);\"> " + item[1] +"</td>" ;
    
                for(int j=2;j<item.Length; j++) // to add sub items of each item and behave like list view.
                {
                    HtmlList += "<td > " + item[j] +"</td>" ;
    
                }
    
                HtmlList += "</tr>";
            }
            HtmlList = HtmlList + "</tbody></TABLE>";
            return HtmlList;
        }
        catch(Exception ex)
        {
            HtmlList = HtmlList + "</tbody></TABLE>";
            return ex.Message;
        }
    }
    
    public  string getList()
    {
        String HtmlList = String.Empty;
        ArrayList al = new ArrayList();
    
        for(int i=0; i<10; i++)
        {
            string[] item = new string[2];
    
            item[0] = "ServerDown.jpg"; // for a list box with images
    
            // Main item to select
            item[1] = "MainItem_" + i.ToString();
        
            al.Add(item); //add item in array list
        }
        string[] bigItem = new string[2];
        bigItem[0] = "";
        bigItem[1] = "abcdefghijklmnopqrestuvwxyz";
        al.Add(bigItem);
        return Render(al);
    }
    
    public void Page_Load(object obj, System.EventArgs e)
    {
          if(!IsPostBack)
          {
            selVal.Value = "";
          }
    
    }
    
    public void cmdOK_Click(object obj, System.EventArgs e)
    {
           lblInfo.Text = selVal.Value;
    }

Open in new window

FigleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anurag ThakurTechnical ManagerCommented:
in your getList() function there is a look up to 10 for adding 10 items to the array list
instead of that for loop you need to loop for all the lines in the text file and add the line text in item[1] and if you know what image needs to be shown you need to update that in item[0].

the solution can be provided better if we know what kind of format the text file has from which you need to populate the arraylist
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FigleAuthor Commented:
aw sorry its a .txt text file from notepad
0
FigleAuthor Commented:
would i need to use a for each to beable to reference each line of text from the .txt file to my ping and display it like i did in the below code?
protected void Page_Load(object sender, EventArgs e)
    {
        string[] servers = File.ReadAllLines(Server.MapPath("TestFile.txt"));
        foreach (string svr in servers)
        {
            PingSvr(svr);  
        }
    }
 
    public void PingSvr(string hostName)
    {
            Ping pingSender = new Ping(); PingOptions options = new PingOptions();
            // Use the default Ttl value which is 128,
 
            // but change the fragmentation behavior. 
            options.DontFragment = true;
 
            // Create a buffer of 32 bytes of data to be transmitted. 
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
 
            byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);
            int timeout = 120;
            //hostName = svr;
            PingReply reply = pingSender.Send(hostName, timeout, buffer, options);
 
            if (reply.Status == IPStatus.Success)
            {  
                ListBox1.Items.Add(hostName + " is Online");
               
                serverstatus2.ImageUrl = "~/ServerUp.jpg";
            }
 
            else
            {
                ListBox1.Items.Add(hostName + " is Down");
                
                serverstatus2.ImageUrl = "~/ServerDown.jpg";
            }
      
    }

Open in new window

0
FigleAuthor Commented:
I figured it out,i really got to stop over anazling stuff, thanks for ya help!
0
FigleAuthor Commented:
Could used more detailed insructions and maybe some code examples but thanks for the help thou!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.