Question: how to organize dynamic data for multiple FlexBoxes in a page?

Oct 13, 2010 at 6:38 PM

We have a page where 5 controls can be replaced with FlexBox. The data for the controls are in different tables in DB.  It seems we need create one .aspx page for every FlexBox control. This seems not so clean. Is there any better to manage the code for dynamic data? For example, is it possible to have 5 methods in a single .aspx page to provide data for all the controls?

Also it seems to me the way of providing JSON data by .aspx page is not so clean either because the response is not actually a page. Is it possible to use web service to feed data? I have little knowledge about jQuery and JSON. If my question does not make sense at all, please do not laugh at me.

Thanks.

Dec 26, 2010 at 2:27 PM

do it like this ...

 

 
 <script>
 $(function() {

         $('#fb').flexbox('GetDataPage.aspx?Page=campustype', {
             autoCompleteFirstMatch: true,
             noResultsText: 'No results found',
             allowInput: false,
             showArrow: true,
             resultTemplate: '<div class="col2" style="width:140px;">{name}</div>',
             watermark: '--All Campus Types--',
             width: 143,
             onSelect: function() {
                 var selId = this.getAttribute('hiddenValue');
                 $('#ctl00_hiddenid').val(selId);

             }
         });
       
     

     });

 </script>

 

  private string qstr = "";
  StringBuilder sbmod = new StringBuilder();
  protected void Page_Load(object sender, EventArgs e)
    {
        // Clear out the buffer
        Response.ClearHeaders();
        Response.ClearContent();
        Response.Clear();

        // Do not cache response
        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        // Set the content type and encoding for JSON
        Response.ContentType = "application/json";
        Response.ContentEncoding = Encoding.UTF8;

        string query = Request["q"];
        int page = int.Parse(Request["p"]);
        int size = int.Parse(Request["s"]);

        //---------------------------------------
        
        Int32 cnt = 0;
        int flag = 0;
        try
        {
            string xx = Request.QueryString["xxx"].ToString();
       
        }
        catch { }

        switch (Request.QueryString["Page"].ToString())
        {
            case "campustype":
                qstr = " SELECT ROW_NUMBER()OVER(ORDER BY id) AS id,name" +
                       " FROM (select distinct campus as id, campus as name" +
                       " from v_school_campus_program) v_school_campus_program";
                //add campus and programs in the criteria
                break;
            case "degree":
                qstr = "select distinct levelid as id,degree as name" +
                       " from v_school_campus_program " +
                       " inner join t_degree on levelid =id " +
                       " where enabled = 1";
                //if (_campusTtype!="")
                //{
                //    qstr = qstr + "and campus='"+  +"'";
                //}
                //add campus and programs in the criteria
                break;
            case "programs":
                qstr = "select distinct id as id, program as name " +
                       " from t_program inner join " +
                       " v_school_campus_program v " +
                       " on id = v.parentid";
                //add campus and programs in the criteria
                break;
        }
        sbmod.Append("{\"results\":[");
        if (qstr != "")
        {
            DataSet _dataSet = null;
            DataTable _dt = null;
            try
            {
                _dataSet = BL.GenericDataset(qstr);
                _dt = _dataSet.Tables[0];
                cnt = _dt.Rows.Count;
                for (int i = 0; i <= cnt; i++)
                {
                    if (!(i == cnt - 1))
                    {
                        if (cnt > 0)
                        {
                            switch (Request.QueryString["Page"].ToString())
                            {
                                case "campustype":
                                    if (flag == 0)
                                    {
                                        sbmod.AppendLine("{\"id\":" + i + ",\"name\":\"" + "--All Campus Types--" + "\"},");
                                        flag = 1;
                                    }
                                    break;
                                case "degree":
                                    if (flag == 0)
                                    {
                                        sbmod.AppendLine("{\"id\":" + i + ",\"name\":\"" + "--All Degree Levels--" + "\"},");
                                        flag = 1;
                                    }
                                    break;
                                case "programs":
                                    if (flag == 0)
                                    {
                                        sbmod.AppendLine("{\"id\":" + i + ",\"name\":\"" + "--All Programs--" + "\"},");
                                        flag = 1;
                                    }
                                    break;
                            }

                        }
                        sbmod.AppendLine("{\"id\":" + _dt.Rows[i]["id"] + ",\"name\":\"" + _dt.Rows[i]["name"] + "\"},");
                    }
                    else
                    {
                        sbmod.AppendLine("{\"id\":" + _dt.Rows[i]["id"] + ",\"name\":\"" + _dt.Rows[i]["name"] + "\"}");
                    }
                }
            }
            catch { }
            finally
            {
                _dataSet.Dispose();
                _dt.Dispose();
            }
        }

        sbmod.Append("],\"total\":\"" + cnt + "\"}");

        Response.Write(sbmod.ToString());


        // Flush the response buffer
        Response.Flush();

        // Complete the request.  NOTE: Do not use Response.End() here,
        // because it throws a ThreadAbortException, which cannot be caught!
        HttpContext.Current.ApplicationInstance.CompleteRequest();

    }