Server controls in an asp.net repeater

前端 未结 3 757
时光取名叫无心
时光取名叫无心 2021-01-15 09:54

Seems like I\'ve ran into a wall here. I want some datasource to be bound to an asp.net repeater (well, doesn\'t have to be a repeater, but it seems like that\'s what I want

3条回答
  •  野的像风
    2021-01-15 10:38

    You can use the Repeater.ItemDataBound Event to locate controls nested in a Repeater.

    
       
          

    Then in code behind:

    protected void Repeater1_ItemDataBound(object source, RepeaterCommandEventArgs e)
    {
       if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=
          ListItemType.AlternatingItem)
          return;
    
       TextBox textBox1 = e.Item.FindControl("TextBox1") as TextBox;
       if (textBox1 != null)
       {
       // do something with it
       }
    }
    

提交回复
热议问题