Guest User

menu.aspx.cs

a guest
Jan 21st, 2011
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Configuration;
  10.  
  11.  
  12. public partial class _Default : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (Request.QueryString["callback"] != null)
  17.         {
  18.             SqlConnection con = new SqlConnection();
  19.             con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
  20.             if (con.State == ConnectionState.Closed)
  21.             {
  22.                 con.Open();
  23.             }
  24.             String outputText = Request.QueryString["callback"].ToString() + "(" + "{";
  25.  
  26.             SqlCommand cmd = new SqlCommand("select id,name from profiles", con);
  27.             SqlDataReader dr = cmd.ExecuteReader();
  28.             var yourlist1 = new List<String>();
  29.             var yourlist2 = new List<String>();
  30.             if (dr.HasRows)
  31.             {
  32.                 while (dr.Read())
  33.                 {
  34.                     yourlist1.Add('"' + dr[0].ToString() + '"' + ":" + '"' + dr[1].ToString() + '"');
  35.                 }
  36.             }
  37.             Array k = yourlist1.ToArray();
  38.             outputText += Convert.ToString(k.GetValue(0));
  39.             for (Int32 i = 1; i < k.Length; i++)
  40.             {
  41.                 outputText += "," + Convert.ToString(k.GetValue(i));
  42.             }
  43.             outputText += "}" +");";
  44.  
  45.             Response.Write(outputText);
  46.             dr.Close();
  47.             cmd.Dispose();
  48.             con.Close();
  49.         }
  50.     }
  51.     protected void Button1_Click(object sender, EventArgs e)
  52.     {
  53.         SqlConnection con = new SqlConnection();
  54.         con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
  55.         if (con.State == ConnectionState.Closed)
  56.         {
  57.             con.Open();
  58.         }
  59.         SqlCommand cmd = new SqlCommand("select id,name from profiles", con);
  60.         SqlDataReader dr = cmd.ExecuteReader();
  61.         var yourlist1 = new List<String>();
  62.         var yourlist2 = new List<String>();
  63.         if (dr.HasRows)
  64.         {
  65.             while (dr.Read())
  66.             {
  67.                 yourlist1.Add('"' + dr[0].ToString() + '"' + ":" + '"' + dr[1].ToString() + '"');
  68.             }
  69.         }
  70.         Array k = yourlist1.ToArray();
  71.         //classic logic
  72.         Response.Write("(" + "{");
  73.         //
  74.         for (Int32 i = 0; i < k.Length; i++)
  75.         {
  76.             Response.Write(Convert.ToString(k.GetValue(i)) + ",");
  77.         }
  78.         //
  79.         Response.Write("}" + ")");
  80.         dr.Close();
  81.         cmd.Dispose();
  82.         con.Close();
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment