Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have dynamically created several HtmlTableCell and several TextBox inside the ItemDataBound of my Repeater. I named inside the ForEach with txt1, txt2, etc. When I click the edit button, I need to access them via ItemCommand to put Enable=true, but I can not because, for some reason, my Repeater just lets me access the controls I inserted into the aspx page. I've tried everything, I can not access the TextBox ... If someone can help me, I'll be very grateful. In time: as you can see in the example below, I inserted the TextBox inside the HtmlTableCell object because the columns are dynamic too ...

What I have tried:

C#
/* my Repeater ItemDataBound */
int i = 1;
for(int i = 1; i <= 24; ++i)
{
   double qtd = com.STRTODOUBLE(HI.ToString());
   
   TextBox txtQTD = new TextBox()
   {
      ClientIDMode = ClientIDMode.Static,
      ID = e.Item.ItemIndex.ToString() + "_" + i.ToString(),
      CssClass = "form-control text-center h5 small",
      MaxLength = 12,
      Text = qtd.ToString("n1"),
      Enabled = false
   };

   HtmlTableCell htc = new HtmlTableCell();
   htc.Attributes.Add("class", "text-right");
   htc.Controls.Add(txtQTD);
   tr.Controls.Add(htc);
   ++i;
}

/* my Repeater ItemCommand */
...
if (e.CommandName.ToString() == "HSG")
{
   for (int i = 1; i <= 24; ++i)
   {
      /* I can access any control that was added in the aspx page, but the dynamic control below always returns null value */ 
      TextBox txtQTD = (TextBox)e.Item.FindControl(e.Item.ItemIndex.ToString() + "_" + i.ToString());
      txtQTD.Enabled = true;
      ++i;
   }
}
Posted

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