Exemple #1
0
    public static string[] HtmlRowsForMakes(string szRestrict, int skip, int pageSize)
    {
        List <string> lst = new List <string>();

        // We have no Page, so things like Page_Load don't get called.
        // We fix this by faking a page and calling Server.Execute on it.  This sets up the form and - more importantly - causes Page_load to be called on loaded controls.
        using (Page p = new FormlessPage())
        {
            p.Controls.Add(new HtmlForm());
            using (StringWriter sw1 = new StringWriter(CultureInfo.CurrentCulture))
                HttpContext.Current.Server.Execute(p, sw1, false);

            ModelQuery mq = JsonConvert.DeserializeObject <ModelQuery>(szRestrict);
            mq.Skip  = skip;
            mq.Limit = pageSize;

            foreach (MakeModel m in MakeModel.MatchingMakes(mq))
            {
                Controls_mfbMakeListItem mli = (Controls_mfbMakeListItem)p.LoadControl("~/Controls/mfbMakeListItem.ascx");
                HtmlTableRow             tr  = new HtmlTableRow();
                p.Form.Controls.Add(tr);
                HtmlTableCell tc = new HtmlTableCell();
                tr.Cells.Add(tc);
                tc.VAlign = "top";
                tc.Controls.Add(mli);
                // Now, write it out.
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = null;
                try
                {
                    sw = new StringWriter(sb, CultureInfo.CurrentCulture);
                    using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                    {
                        sw = null;
                        try
                        {
                            mli.SortMode = mq.SortMode;
                            mli.Model    = m;
                            mli.ModelLink.NavigateUrl = VirtualPathUtility.ToAbsolute(mli.ModelLink.NavigateUrl);
                            tr.RenderControl(htmlTW);
                            lst.Add(sb.ToString());
                        }
                        catch (ArgumentException ex) when(ex is ArgumentOutOfRangeException)
                        {
                        }                                                                         // don't write bogus or incomplete HTML
                    }
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Dispose();
                    }
                }
            }
        }

        return(lst.ToArray());
    }
 protected void MakesRowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e != null && e.Row.RowType == DataControlRowType.DataRow)
     {
         Controls_mfbMakeListItem mli = (Controls_mfbMakeListItem)e.Row.FindControl("mfbMakeListItem1");
         MakeModel mm = (MakeModel)e.Row.DataItem;
         mli.Model = mm;
         mli.ModelLink.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "{0}/{1}", Request.Url.LocalPath, mm.MakeModelID);
     }
 }
 protected void MakesRowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         Controls_mfbMakeListItem mli = (Controls_mfbMakeListItem)e.Row.FindControl("mfbMakeListItem1");
         ModelQuery mq = ActiveQuery;
         mli.SortMode = mq.SortMode;
         mli.Model    = (MakeModel)e.Row.DataItem;
     }
 }