Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["role"] != null)
            {
                if (Session["role"].ToString() == "user")
                {
                    Response.Redirect("~/Website%20(Front-End)/Shop.aspx");
                }
            }
            else
            {
                Response.Redirect("~/Website%20(Front-End)/LoginUser.aspx");
            }

            if (!Page.IsPostBack)
            {
                String strConnString;
                strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                                Server.MapPath("~/App_Data/simplyalmonds.mdb") + ";";
                objConn = new OleDbConnection(strConnString);
                objConn.Open();

                // Intial load of Latest Events and News
                strSQL = "SELECT * FROM Shop where ProductType='Ticket'";

                OleDbDataReader dtReader;
                objCmd   = new OleDbCommand(strSQL, objConn);
                dtReader = objCmd.ExecuteReader();

                TicketRepeater.DataSource = dtReader;
                TicketRepeater.DataBind();

                strSQL   = "SELECT * FROM Shop where ProductType='Single'";
                objCmd   = new OleDbCommand(strSQL, objConn);
                dtReader = objCmd.ExecuteReader();

                SingleRepeater.DataSource = dtReader;
                SingleRepeater.DataBind();

                dtReader.Close();
                objConn.Close();
            }
        }
Example #2
0
        /// <summary>
        /// Repeater
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="helper"></param>
        /// <param name="dataSource">数据源</param>
        /// <param name="header">第一个单项循环开始之前的内容</param>
        /// <param name="itemTempletes">单项内容</param>
        /// <param name="separatorTemplate">每次循环分隔内容(Table慎用)</param>
        /// <param name="footer">最后一个单项循环结束之后的内容</param>
        /// <param name="repeaterMode">repeater模式</param>
        /// <param name="colCount">每行烈数(只在repeaterMode为Table时有效)</param>
        /// <param name="htmlAttributes">标签属性</param>
        /// <returns></returns>
        public static string Repeater <T>(this HtmlHelper helper, IEnumerable <T> dataSource,
                                          string header, Expression <Func <T, int, string> > itemTempletes, Expression <Func <T, string> > separatorTemplate, string footer,
                                          RepeaterMode repeaterMode, int colCount, object htmlAttributes)
        {
            if (dataSource == null)
            {
                return("");
            }

            HttpContext context = helper.ViewContext.HttpContext;

            //Dictionary<object, object> data = MvcControlDataBinder.SourceToDictionary(dataSource, "", "");
            SingleRepeater repeater = new SingleRepeater(context, repeaterMode, htmlAttributes);

            using (repeater)
            {
                StringBuilder         body            = repeater.body;
                Func <T, int, string> itemResult      = itemTempletes.Compile();
                Func <T, string>      separatorResult = separatorTemplate.Compile();


                //header
                body.Append(header);

                int tableRow = 0;

                /** 单项循环开始 **/

                int dataCount = dataSource.Count();
                int i         = 0;
                foreach (var item in dataSource)
                {
                    /* 仅适用Table */
                    if (repeaterMode == RepeaterMode.Table)
                    {
                        if (tableRow % colCount == 0)
                        {
                            body.Append("<tr>");//添加行开始标记
                        }
                    }

                    body.Append(repeater.itemStartTag);//单项开头

                    switch (repeaterMode)
                    {
                    case RepeaterMode.None:
                    case RepeaterMode.Div:
                    case RepeaterMode.Ul:
                    case RepeaterMode.Table:
                        body.Append(itemResult(item, i).ToString());    //主体内容
                        break;
                    }

                    body.Append(repeater.itemEndTag);//单项结尾

                    /* 仅适用Table */
                    if (repeaterMode == RepeaterMode.Table)
                    {
                        tableRow++;
                        if (tableRow % colCount == 0)
                        {
                            body.Append("</tr>");//添加行结束标记
                        }
                    }

                    //添加分隔符
                    if (i < dataCount - 1)
                    {
                        body.Append(separatorResult(item).ToString());
                    }

                    i++;
                }
                /** 单项循环结束 **/


                //为Table添加结束标记
                if (repeaterMode == RepeaterMode.Table && tableRow % colCount != 0)
                {
                    do
                    {
                        body.Append(repeater.itemStartTag).Append(repeater.itemEndTag);//空白单元格
                        tableRow++;
                    } while (tableRow % colCount != 0);
                    body.Append("</tr>");
                }
                //context.Response.Write(body.ToString());

                //footer
                body.Append(footer);
            }
            return(repeater.ToString());
        }