Philo <[EMAIL PROTECTED]> wrote: >Here's what I'm trying to do: >A web form has a drop down list and a bunch of text boxes. Selecting a >value from the dropdown list populates the text boxes. (Without a round >trip to the webserver) > >In ASP I'd build a javascript array with the potential values and call a >function in the onchange event of the dropdownlist to populate the text >boxes. > >I can figure everything out except building the array from the database - >how do I do this?
Assuming you've already got a DataSet from the DB, just add this in your ASPX: <head> <script language="Javascript"> <%= RenderArray(myDataSet.Tables["myArrayTable"]) %> </script> </head> Then just define a method in your page or codebehind class like so: <codeSnippet language="C#"> private static void RenderArray(DataTable table) { HttpResponse response = HttpContext.Current.Response; DataRowCollection tableRows = table.Rows; cont string ArrayElementFormatString = "dataArray[{0:D}]=new Array ("{1}", "{2:d}", "{3:D}");" response.Write("var dataArray = new Array();") for(int rowIndex = 0; rowIndex < tableRows.Count; rowIndex++) { DataRow row = tableRows[rowIndex]; string arrayElementString = String.Format(ArrayElementFormatString, rowIndex, row["name"], row["date"], row["age"]); response.Write(arrayElementString); } } </codeSnippet> Depending on the data in your name field you may also need to escape the string so it doesn't mess up the JavaScript definition (i.e. if it can contain quotes). HTH, Drew .NET MVP You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.