Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array
Using a Dataset to populate javascript array Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Go Back  Xtreme Visual Basic Talk > > > Using a Dataset to populate javascript array


Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2006, 10:59 PM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default Using a Dataset to populate javascript array


does anyone know how to do this?

Code:
function namelist() {
    this.names= [];
}
how can I put the contents of a datatable (populated using serverside) inside the names array declared in javascript?

all suggestions are appreciated.
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #2  
Old 12-19-2006, 08:29 AM
wayneph's Avatar
waynephUsing a Dataset to populate javascript array wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

I guess you could use a Repeater, and just put asp:Literal controls in it. Or build it in the code behind and loop through it manually.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 12-19-2006, 05:51 PM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

I think I should.

What I am trying to build now is an invisible listbox and point the contents to the java array. problem is, the java function is called during window.onload and I am populating the listbox on the page_load. This is wrong.. right?
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #4  
Old 12-20-2006, 08:53 AM
wayneph's Avatar
waynephUsing a Dataset to populate javascript array wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

you're going to have to be a lot more specific. i can't see your code to understand your question.

how are you calling the function? Have you tried using Page.RegisterStartUpScript() to add the JS code to your page?
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 12-26-2006, 05:33 PM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

well this is how I call the function

Code:
<script type="text/javascript"> window.onload = function () { var oTextbox = new AutoSuggestControl(document.getElementById("txtremlname"), new NameList()); } </script>

but this is during the .onload event.
and hte problem is, the dataset is poputaed during the Page_Load event.
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #6  
Old 12-26-2006, 11:13 PM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

ok I have updated a little and this is what I have right now:

Code:
Private Sub suggestions() Dim ws As New obpwebservice.remitter Dim myDS As New DataSet Dim strSuggest As New StringBuilder Dim lnCtr As Int16 Dim stringko As String Try ws.getRemitterByName(myDS, " ", "") For lnCtr = 0 To myDS.Tables(0).Rows.Count - 1 stringko = stringko & "''" & myDS.Tables(0).Rows(lnCtr)("lastname") & "''," Next txtSuggestions.Text = Mid(stringko, 3, Len(stringko) - 4) Catch ex As Exception Me.lbl_Error.Text = ws.errormsg End Try ws = Nothing End Sub

this is how I create stringko and place it inside a textbox (txtSuggestions)

and then

I have this:

Code:
<script type="text/javascript">
            window.onload = function () {
                var oTextbox = new AutoSuggestControl(document.getElementById("txtremlname"), new NameList());        
                       }
		</script>
in the HTML code..
and this:

Code:
function NameList() 
{
    this.Names = [document.getElementById("txtSuggestions.value")];
}
is what Namelist now looks like.

I am in total darkness as to which these functions/procedures are fired first.
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #7  
Old 12-27-2006, 10:03 AM
wayneph's Avatar
waynephUsing a Dataset to populate javascript array wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

you're missing one key point. your dataset is on the serverside, but the rest of your code is running on the client side.

also your NameList function isn't using a valid element. I assume you're binding your DataSet to the txtSuggestions control? but to get anything, you'll need to use document.getElementById("txtSuggestions"), not txtSuggestions.value. That's invalid JavaScript no matter what you're trying to do.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #8  
Old 01-09-2007, 01:18 AM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

this is where this task got to its final version.
I'm posting this for those who are trying to do this.

This is the server-side code to get all the data.

Code:
Private Sub suggestions() Dim ws As New obpwebservice.remitter Dim myDS As New DataSet Dim strSuggest As New StringBuilder Dim lnCtr As Int16 Dim stringko As String Try ws.getRemitterByName(myDS, " ", "") For lnCtr = 0 To myDS.Tables(0).Rows.Count - 1 stringko = myDS.Tables(0).Rows(lnCtr)("lastname") & ", " & stringko Next txtSuggestions.Value = stringko Hidden1.Value = myDS.Tables(0).Rows.Count Catch ex As Exception Me.lbl_Error.Text = ws.errormsg End Try ws = Nothing End Sub

I placed all the values in a Hidden Textbox and added a comma as separator.
then I added this to the HTML code:

Code:
<script type="text/javascript"> window.onload = function () { var oTextbox = new AutoSuggestControl(document.getElementById("txtremlname"), new NameList()); } </script>

this assigns txtremlname as a textbox with "autosuggest feature"
and this is how the data is 'transferred' from the hidden textbox

Code:
var Names = new Array(); function NameList() { Names.length = parseInt(document.getElementById('Hidden1').value); var stringer = document.getElementById('txtSuggestions').value; for (var x = 0; x < Names.length; x++) { Names[x] = stringer.substring(0, stringer.indexOf(',')); stringer = stringer.substring(stringer.indexOf(', ') +2, stringer.length); } } NameList.prototype.requestSuggestions = function (oAutoSuggestControl) { var aSuggestions = []; var sTextboxValue = oAutoSuggestControl.textbox.value; if (sTextboxValue.length > 0){ for (var i=0; i < Names.length; i++) { if (Names[i].indexOf(sTextboxValue) == 0) { aSuggestions.push(Names[i]); } } } oAutoSuggestControl.autosuggest(aSuggestions); };

basically stringer gets the string and adds it to NameList.

I could not have done this without WaynePH's help in using the getelementbyid thing..

thanks wayne.. you da man!
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
 
Using a Dataset to populate javascript array
Using a Dataset to populate javascript array
 
-->