By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,210 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,210 IT Pros & Developers. It's quick & easy.

How to set visibility of a control in DataList template?

P: n/a
I want to set the visible of pnlEditButton according to current login.
However, the control is not a member of this(Page) and FindControl() returns

protected void Page_Load(object sender, System.EventArgs e)
bool isAdmin = User.IsInRole("Administrators");
this.FindControl("pnlEditButton").Visible = isAdmin;

<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource1"
<div class="membercard">
<asp:panel id="pnlEditButton" runat="server">


Jul 2 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

hello nick

for templated controls, such as the DataList, you'd normally use
FindControl either during the ItemCreated or ItemDataBound events of
the the control, since you'd have to find a control which is rendered
for each row in the list, that is, you'd have to look for a
pnlEditButton for each row before you can set it.

for an example of coding the handler for the ItemCreated event

void setButton ( Object src, DataListItemEventArgs e ) {
if ( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem ) {
Panel pnlEditButton = ( Panel ) e.Item.FindControl (
"pnlEditButton " );
pnlEditButton.Visible = User.IsInRole("Administrators") ;

or something like that

Jul 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.