I am using ASP.net to develop this website and i need to pass my arraylist to javascript so that i can use those numbers and values to create a chart using jqPlot.
i Have a class called,
public class ConfidenceLvl
{
private string ip;
private string isp;
private int conLvl;
public string Ip
{
get { return ip; }
set { ip = value; }
}
public string Isp
{
get { return isp; }
set { isp = value; }
}
public int ConLvl
{
get { return conLvl; }
set { conLvl = value; }
}
public ConfidenceLvl(string ipVal, string ispVal, int conLvlVal) {
this.conLvl = conLvlVal;
this.ip = ipVal;
this.isp = ispVal;
}
}
and i use this code to insert the values to my arraylist,
ArrayList conRc = new ArrayList();
while (readIp.Read())
{
string ipVal = readIp.GetString(0);
string ispVal = readIp.GetString(1);
int conLvlVal = readIp.GetInt32(2);
conRc.Add(new ConfidenceLvl(ipVal,ispVal,conLvlVal));
}
correlate.Value = ArrayListToString(ref conRc);
And this is the function that is used to format the array to pass to the javascript,
private string ArrayListToString(ref ArrayList _ArrayList)
{
int intCount = 0;
string strFinal = "";
foreach (object obj in _ArrayList)
{
ConfidenceLvl cnLv = (ConfidenceLvl)obj;
String ip = cnLv.Ip;
String isp = cnLv.Isp;
int conLvl = cnLv.ConLvl;
if (intCount > 0)
{
strFinal += "~";
}
strFinal += "IP:" + ip + " ISP:" + isp + " Confidence:" + conLvl.ToString();
intCount += 1;
}
return strFinal;
}
Ans this is the html side code that captues the value passed,
<asp:HiddenField ID="correlate" value= "" runat="server" />
<script language="javascript" type="text/javascript">
var iplistString = document.getElementById('correlate').value;
var iplistArray = iplistString.split('~');
for (var i = 0; i < iplistArray.length; i++) {
alert(iplistArray[i]);
}
</script>
But this bets it as a whole string not seperate values,
I want to pass this to javascript so the can use that integer value (conLvl) to plot the graph using javascript jqPlot. I tried the HiddenField method but it gets all these values as a string. Please help on this issue..Thank you very much :)