locked
Java script array declearation dynamically RRS feed

  • Question

  • How to declare array in java script when i dont know the dimention,

    as it  will form dynamically depending on the rows created from the database.

    I dont have any way to get the rows it comes on run time based on that i will require to create two dimention array for my work  can any body help me.

     


    Please Mark the answers and give points it will help users Thanks & Regards, Kamal Agarwala
    Wednesday, October 13, 2010 7:15 AM

All replies

  • the array in javascript is unlimited, it grows in dimensions as u fill it up. you can create the array from your code in this way:

     

    StringBuilder script = new StringBuilder();

                    script.Append("<script>var list = new Array();");

                    for (int i = 0; i < DataTable.Rows.Count; i++)

                    {

                        script.Append(@"list[" + i + @"]= """ + DataTable.Rows["ColName"] + @""";");

                    }

                    script.Append("</script>");

                    Page.RegisterClientScriptBlock("my script", script.ToString());

     

    and you can create a 2 dimensional arrays if you set an array inside another one


    Suha Mneimneh Team Leader IDS - Integrated Digital Systems
    Tuesday, October 19, 2010 6:21 AM
  • Hi Suha Mneimneh,

     

    I am new to the programing.

    I have all the things comming dynamically.

    The project is in asp and the table has been created dynamically so how to take the row count.

    will the table created dynamically have the row count.

     


    Please Mark the answers and give points it will help users Thanks & Regards, Kamal Agarwala
    Tuesday, October 19, 2010 7:06 AM
  • yes sure, once you fill in your data table you can do the following

    DataTable dt = new DataTable();

     

    for (int i = 0; i< dt.Rows.Count; i++)

    {

    //...... do your loop here

    }

    and the dt.Rows is considered as an array of DataRow 

     


    Suha Mneimneh Team Leader IDS - Integrated Digital Systems
    Tuesday, October 19, 2010 7:10 AM
  • Thanks a lot

     

    I will try this concept and let u know.

     


    Please Mark the answers and give points it will help users Thanks & Regards, Kamal Agarwala
    Tuesday, October 19, 2010 7:28 AM
  • I don't quite understand the problem. If the rows come during runtime, just generate the JavaScript for the arrays after the database creates the rows. Am I missing something?


    Nathan Sokalski
    njsokalski@hotmail.com
    http://www.nathansokalski.com/

    "Kamal Agarwala" wrote in message news:005d5e4e-ace9-4331-a9aa-fa95d05c636f@communitybridge.codeplex.com...

    How to declare array in java script when i dont know the dimention,

    as it  will form dynamically depending on the rows created from the database.

    I dont have any way to get the rows it comes on run time based on that i will require to create two dimention array for my work  can any body help me.


    Please Mark the answers and give points it will help users Thanks & Regards, Kamal Agarwala


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
    Friday, October 22, 2010 8:17 PM
  • Hi,

    You can create a dinamical array in JS using the object Array():

    var myArray = new Array();
    myArray.push('Item 1');
    myArray.push('Item 2');

    I hope it helps!

    Tiago Faveri

    Thursday, January 27, 2011 2:05 PM