C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

VB.Net Arraylist and Javascrip


Posted Date: 20 Nov 2008      Posted By: Raj Sharma      Member Level: Gold     Points: 1   Responses: 1



I have arraylist which having record i want to pass arrraylist in javascript through asp.net codebehind.

and how to receive in javascript and get the whole record.


i am using asp.net with VB.net


Thanks in Advance
Raj





Responses

Author: Venkat Tammineni    20 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

hi,

Once you have your array list populated, you can loop through it and piece together a string. Then simply put this string in a hidden field to make it accessible to javascript.

Detailed example:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim List as New ArrayList()

'Populate Array List

HiddenField1.Value = ArrayListToString(List)
End Sub

Private Function ArrayListToString(ByRef _ArrayList as ArrayList) As String
Dim intCount as Integer
Dim strFinal as String = ""

For intCount = 0 to _ArrayList.Items.Count - 1
If intCount > 0
strFinal += "~"
End If

strFinal += _ArrayList.Items(intCount).ToString
Next

Return strFinal
End Function



Now in javascript, retrieve the data like this:

<script language="javascript" type="text/javascript">
window.onload = function() {
var listString = document.getElementById('HiddenField1').value;
var listArray = listString.split('~');

// Now you have an array in javascript of each value

for(var i = 0; i < listArray.length; i++) {
alert(listArray[i]);
}

}
</script>

Thanks



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Webpage Loading Slow
Previous : doubts of session variable
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use