Accessing Textboxes in Repeater Control

前端 未结 3 882
栀梦
栀梦 2020-12-14 16:58

All the ways I can think to do this seem very hackish. What is the right way to do this, or at least most common?

I am retrieving a set of images from a LINQ-to-SQL

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 17:26

    Have you tried something like following on the button click:-

    foreach (RepeaterItem item in Repeater1.Items)
    {
          TextBox txtName= (TextBox)item.FindControl("txtName");
          if(txtName!=null)
          {
          //do something with txtName.Text
          }
          Image img= (Image)item.FindControl("Img");
          if(img!=null)
          {
          //do something with img
          }
    }
    

    /* Where txtName and Img are the Ids of the textbox and the image controls respectively in the repeater.*/

    Hope this helps.

提交回复
热议问题