从转发器中检索值 [英] Retrieving a value from a repeater

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

问题描述

大家好,



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



我使用以下内容访问转发器,但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();
}
}
}
}

解决方案

请阅读这个 [ ^ ]了解如何访问模板内的控件...


FindControl 一次适用于一行/项目。



参考 - RepeaterItem.FindControl方法 [ ^ ]。

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();
                    }
                }
            }
        }

解决方案

Please read this[^] to understand how to access controls inside a template...


FindControl works for one Row/Item at a time.

Refer - RepeaterItem.FindControl Method[^].


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆