c# - 如何访问每个循环的 html 属性以进行编码?

标签 c# asp.net

我正在尝试访问代码隐藏文件中的这些数据。如果我将这些 html 标签更改为 asp 标签,我将无法从每个循环中检索数据。在这里,我想要每个循环生成的实际销售价格和产品尺寸,以将这些属性保存在数据库中。那么有什么办法可以解决这些问题吗??

aspx 页面

        <%
                foreach (Com.Idk.Application.ImaraResPOS.Entities.ProductSize psize in psList)
                    { 
                %>
                <div class="col-sm-12  text-center type">

                    <div class="circle bg">
                        <img src="images/Meal-100.png">
                    </div>
                    <div class="btn-align-size">

                        <button class="btn btn-primary ladda-button cd-add-to-cart" data-price="<%=psize.SalesPrice %>" data-name="<%= psize.SizeDef.Name %>" data-product-image="images/3.jpg" data-style="expand-right" id="Breadtype_btn" data-dismiss="modal" data-toggle="modal" data-target="#bread_type">
                            <%= psize.SizeDef.Name %>
                            <img src="images/Buy-30.png" style="height: 30px; width: 30px">
                            <h3 class="hide">
                                <%= psize.Id%>
                            </h3>

                        </button>

                    </div>
                </div>

                <%

                    }

                %>

代码隐藏

 private void InsertProductSizeToSale()
    {
          string sizeID = Request.QueryString["size_id"].ToString();

        Com.Idk.Application.ImaraResPOS.Entities.ProductSize prid = new Com.Idk.Application.ImaraResPOS.Entities.ProductSize();

        psList.Select(Global.sess, "ProductSize","where Product_ID="+ prid);
        if (psList.Count > 0)
        {

            Hashtable parameterList = new Hashtable();
            OfferDetailList odList = new OfferDetailList();


            parameterList.Clear();
            parameterList.Add("productSizeId", sizeID );
            parameterList.Add("comboId", null);

            parameterList.Add("currentDate", DateTimeUtil.GetFormattedString(((Sale)index.saleid).Date));

            parameterList.Add("currentTime", DateTimeUtil.GetFormatedTimeString(DateTime.Now));
            parameterList.Add("day", Const.GetDay(((Sale)index.saleid).Date.DayOfWeek));
            odList.SelectUsingSP(Global.sess, "SqlProGetOfferDetail", parameterList);

            if (odList.Count == 0)
            {
               //want to retrive psize properties here
               // here i'm getting an error

               SqlProInsertProductSizeToSale(prid, sizeID, psize.SalesPrice, psize.SalesPrice);
            }
            else if (odList.Count > 0)
            {  SqlProInsertProductSizeToSale(selectedProduct, selectedProductSize, odSelection.GetSelectedProductSizePrice(), selectedProductSize.SalesPrice);
             }

            }
        }



    }

最佳答案

我不确定您为什么要从页面获取数据。既然您是从一些实体对象填充页面,为什么不直接从实体对象获取数据呢?

代码隐藏

foreach (Com.Idk.Application.ImaraResPOS.Entities.ProductSize p in psList)
{ 
    SqlProInsertProductSizeToSale(p.prid, p.sizeID, p.SalesPrice, p.SalesPrice);
}

关于c# - 如何访问每个循环的 html 属性以进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237488/

相关文章:

c# - 首次单击异步按钮时,UI 会卡住 5 秒

c# - 使用 Outlook 2007 的 C# 加载项将焦点设置到 "new message"表单中的主题字段

html - 与 Telerik 控件的内置 javascript 函数相关的问题

c# - 在构造函数以外的地方构建结构/对象

c# - 上传到 Azure 后缺少 CSS 过渡效果

asp.net - 这个 Telerik.Web.UI.dll 可以免费使用吗?

asp.net - 在IE 10的DotNetNuke网站上未定义__doPostBack

c# - Web Api 2 或通用处理程序来提供图像?

asp.net - 以编程方式将 HTML 转换为 Markdown 语法

c# - 如何使用 C# 和 NAudio 将 []Int16 转换为 []float?