Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datalist Item 2

Status
Not open for further replies.

1Data

MIS
Sep 30, 2005
66
US
I have a Datalist with a button in it that I need make visibility off and on based on a Session Variable. Can someone help me with this code?

On my page load I have an IF ELSE based on the session variable but don't know how to obtain the visibility property off of that button in my datalist?

I am also having a problem with it the instance of the object I don't know where to put this code..

I appreciate any suggestions and thank you in advance..

 
What do you have so far? Can you post your code?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Oh, and if you were actually asking where you can set the visibility try using the ItemDataBound event.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
You have to use the ItemDataBound event of the DataList:
Code:
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
   Dim btn As New Button
   btn = CType(e.Item.FindControl("button1"), Button)
   If "some condition" Then   
     btn.Visible = False
   End If
End If

Jim
 
These are some great post thank you guys I will try it out...
 
jbenson,

If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then

I am having an issue in my code with this part of your post...the particular button I need is a Linkbutton (with an id of button4) and it's located in the editItemTemplate section of my datalist...here is what I adjusted your post to...

If e.Item.ItemType = ListItemType.EditItem Then
Dim btn As New LinkButton
btn = CType(e.Item.FindControl("button4"), LinkButton)
If Session("Administrator") = "False" Then
btn.Visible = False
End If
End If

it jumps right to the End IF when I step through it...
 
That code will only be "TRUE", if you place the item into edit mode. I am not too familar how you do that with a datalist, usually use datagrids. But the fact remains that it won't be "true" unless you are editing some row of the datalist.

Jim

 
Jim,

Can you post how you would do this with a datagrid...just to give me something I can try?
 
Ok I appreciate it I will see what I can do to make this work...thanks
 
Ok Let me know. Or if there are more questions or problems.. post them.. :)

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top