本文介绍了从转发器中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试从转发器中检索一些数据,最终目标是将一堆数据发送到表中。



我使用以下内容访问转发器,但FindControl有下划线:



  String  prodName =((Literal)Repeater1.ItemTemplate.FindControl(  LitProdName))。文字; 





但是我收到警告:



 错误  1  '  System.Web.UI.ITemplate'不包含'FindControl'的定义并且没有扩展方法'FindControl'接受类型为'System.Web.UI.ITemplate'的第一个参数'(您是否缺少using指令或程序集引用?)C:\ Users \ User \Desktop \\ \\ WLL \ WLL\ProductDetails.aspx.cs 62 68 WLL  





完整的方法如下s:



  public   void  AddToBasket()
{

{
// String prodName =Test;
String prodName =((Literal)Repeater1.ItemTemplate.FindControl( LitProdName))。文字;
字符串 prodID = Request.QueryString [ 的productID];
String userName = User.Identity.Name;
字符串 size = 17.5;
int price = 10 ;

{
var basket = new Basket();

basket.User = userName;
basket.ProductID = Convert.ToInt32(prodID);
// basket.ProductName = prodName;
basket.Size = size;
basket.Price = price;

使用(ProductContext _db = new ProductContext())
{


_db.Baskets.Add(basket);
_db.SaveChanges();
}
}
}
}
解决方案



Hi all,

I'm trying to retrieve some data from a repeater, the end goal is to send a bunch of data in to a table.

I'm using the following to access the repeater, however "FindControl" is underlined:

String prodName = ((Literal)Repeater1.ItemTemplate.FindControl("LitProdName")).Text;



However I get the warning:

"

Error   1   'System.Web.UI.ITemplate' does not contain a definition for 'FindControl' and no extension method 'FindControl' accepting a first argument of type 'System.Web.UI.ITemplate' could be found (are you missing a using directive or an assembly reference?)   C:\Users\User\Desktop\WLL\WLL\ProductDetails.aspx.cs    62  68  WLL

"

The complete method is as follows:

public void AddToBasket()
        {

            {
                //String prodName = "Test";
                String prodName = ((Literal)Repeater1.ItemTemplate.FindControl("LitProdName")).Text;
                String prodID = Request.QueryString["productID"];
                String userName = User.Identity.Name;
                String size = "17.5";
                int price = 10;

                {
                    var basket = new Basket();

                    basket.User = userName;
                    basket.ProductID = Convert.ToInt32(prodID);
                    //basket.ProductName = prodName;
                    basket.Size = size;
                    basket.Price = price;

                    using (ProductContext _db = new ProductContext())
                    {

                      
                        _db.Baskets.Add(basket);
                        _db.SaveChanges();
                    }
                }
            }
        }
解决方案



这篇关于从转发器中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 05:27