Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
How To pass a variable from aspx.cs page to a separate JS file in the same project

Ok so i am fetching data from sql database and i have converted it to json format and stored it in a variabl. And this variable is in the adminBookInventory.aspx.cs .....Now i want to pass this varaible to a separate JS file Named allArtsAndDesignBooks.js ..... anyone here who have any idea about this or have done this before ? i am waiting for your assistance ....

The following code is one of my functions in adminBookInventory.aspx.cs ...

public void getArtsAndDesignBooks() {



            SqlConnection conn = new SqlConnection(connstring);

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand(" SELECT * FROM allArtAndDesignBooks", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            var JSONString = new StringBuilder();
            if (dt.Rows.Count >= 1) {
                JSONString.Append("[");
                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    JSONString.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j < dt.Columns.Count - 1)
                        {
                            JSONString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\",");
                        }
                        else if (j == dt.Columns.Count - 1)
                        {
                            JSONString.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":" + "\"" + dt.Rows[i][j].ToString() + "\"");
                        }
                    }
                    if (i == dt.Rows.Count - 1)
                    {
                        JSONString.Append("}");
                    }
                    else
                    {
                        JSONString.Append("},");
                    }
                }
                JSONString.Append("]");
            }
            var allArtsAndDesignBooks= JSONString.ToString();
        }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!