Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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


However I get the warning:

"
VB
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:

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

Please read this[^] to understand how to access controls inside a template...
 
Share this answer
 
FindControl works for one Row/Item at a time.

Refer - RepeaterItem.FindControl Method[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900