PDA

Click to See Complete Forum and Search --> : how to deal with controls inside datalist


carlblanchard
Mar 1st, 2005, 02:22 PM
Hey All

how can i handle acting with controls inside datalist
i would like to be able to make buttons and controls visable and invisable from the code behind but i havnt got a cue how to do this

Code examples would be nice

thanks in advance

dj4uk
Mar 2nd, 2005, 05:37 AM
The datalist has a collection of DataListItems that contain each item within your datalist. You can access controls within each item by using the FindControl method and then assign the properties you need.

For example if I wanted to set a button control in the 3rd item of a datalist to be hidden I would do:

Button btnExample = (Button) dlstExample.Items[2].FindControl("button");
btnExample.Visible = false;


where

<datalist id="dlstExample" runat="server">
<ItemTemplate>
<asp:Button id="button" runat="server" Text="Test" />
</ItemTemplate>
</datalist>


HTH

DJ