0

The SetVisibility checks against a database if all the buttons should be enabled or not. I want to disable all buttons if setvisility(UserID) == false

This part of the Code disables only alternating up and down buttons. Can someone please suggest why is this happening ?

else { Button b = e.Item.FindControl("btnmoveup") as Button; b.Enabled = false; Button b2 = e.Item.FindControl("btnmovedown") as Button; b2.Enabled = false; } 

Here is the Complete Code:

if (e.Item.ItemType == ListItemType.Item) { String userID = User.Identity.Name.Split('\\')[1]; if (setvisibility(userID) == true) { if (e.Item.ItemIndex == 0) { Button b = e.Item.FindControl("btnmoveup") as Button; b.Enabled = false; } DataView view = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); DataTable result = view.ToTable(); if (e.Item.ItemIndex == (result.Rows.Count) - 1) { Button b2 = e.Item.FindControl("btnmovedown") as Button; b2.Enabled = false; } } else // How to disable all the buttons ? { Button b = e.Item.FindControl("btnmoveup") as Button; b.Enabled = false; Button b2 = e.Item.FindControl("btnmovedown") as Button; b2.Enabled = false; } } 
2
  • Shouldn't Item.HasControls be Item.FindControl? Commented Jun 27, 2012 at 13:40
  • @Duane Yes sorry i did that change now still it has the same error Commented Jun 27, 2012 at 13:46

1 Answer 1

3

Use:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem ) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.