Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:53:05+00:00 2026-06-09T17:53:05+00:00

I have a DataTable that I get from the DB, I want to create

  • 0

I have a DataTable that I get from the DB, I want to create a 2d array in the code behind (once I get the DataTable..), and then pass it as a 2d array to Javascript.

this is what I tried to code :

int[,] videoQarray = new int[dt_questionVideo.Rows.Count,dt_questionVideo.Columns.Count ];
        string[,] videoQarrayTitle = new string[dt_questionVideo.Rows.Count, dt_questionVideo.Columns.Count ];

        for (var i = 0; i < dt_questionVideo.Rows.Count ; i++)
        {
            for (int j = 0; j < dt_questionVideo.Columns.Count; j++)
            {

                videoQarray[i,j] = Convert.ToInt32(dt_questionVideo.Rows[i][0]);
                videoQarrayTitle[i,j] = dt_questionVideo.Rows[i][1].ToString();   
            }
        }

        string createArrayScript = string.Format("var videQarray = [{0}];", string.Join(",", videoQarray));
        createArrayScript += string.Format("var videQarrayList = [{0}];", string.Join(",", videoQarrayTitle));

        Page.ClientScript.RegisterStartupScript(this.GetType(), "registerVideoQArray", createArrayScript, true);

well, in the browser console it says that videoQarray is not defined..
I wonder how can I do that properly..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:53:07+00:00Added an answer on June 9, 2026 at 5:53 pm

    Probably the variable is being defined inside a function and therefore is hidden for other parts of code. Try “window.videoQArray” insted of “var “:

    string createArrayScript = string.Format("window.videQarray = [{0}];", string.Join(",", videoQarray));
    createArrayScript += string.Format("window.videQarrayList = [{0}];", string.Join(",", videoQarrayTitle));
    

    Edit: It’s a 2d array (ok, you wrote that very clearly in the question but I didn’t see). Use JavaScriptSerializer:

    var serializer = new JavaScriptSerializer();
    string createArrayScript = string.Format("window.videQarray = {0};", serializer.Serialize(videoQarray));
    createArrayScript += string.Format("window.videQarrayList = {0};", serializer.Serialize(videoQarrayTitle));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get value from datatable and then store it to the string()
I have a DataSet which I get a DataTable from that I am being
I have 3 collection datatable that shows in this below Month: January ID NAME
I have a untyped DataTable that looks like this (srcTbl): date col_1 col_2 ...
I have a query that, basically, says this: SELECT DISTINCT [DB_ID] FROM [TableX] WHERE
I have the following code used to get xml from a DataSet into a
I have an application that shows some data in p:DataTable.... This table is accessible
I have a DataTable which I get by an upload of CSV document from
I have an older form that I really don't want to rewrite at this
I have a datatable that stores location values as such: CTY_CD, STATE_CD, COUNTRY_CD and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.