I am trying to hide some textboxes, dropdownlists and labels in datalist

D

Dgreer

I am trying to hide some textboxes, dropdownlists and labels in
datalist.

I have some textboxes, dropdownlists and labels in a table in a
datalist how do I hide them after they're bound?

Here is some of my code in the datalist.ItemDataBound Event.

Select Case editvisiblity

Case 1
Dim txt As New TextBox
txt = CType(e.Item.FindControl("etxtPK_User_ID"),
TextBox)
txt.Visible = False
e.Item.FindControl("etxtLastLogin").Visible = False
e.Item.FindControl("etxtCreatedBy").Visible = False
e.Item.FindControl("etxtCreationDate").Visible =
False
e.Item.FindControl("ddlRole").Visible = False
e.Item.FindControl("etxtLocID").Visible = False
e.Item.FindControl("ddlUserLevel").Visible = False
e.Item.FindControl("echkActive").Visible = False
e.Item.FindControl("etxtConfirmPassword").Visible =
False
e.Item.FindControl("etxtPassword").Visible = False
e.Item.FindControl("etxtCofilter").Visible = False

e.Item.FindControl("txtPK_User_ID").Visible = False
e.Item.FindControl("txtLastLogin").Visible = False
e.Item.FindControl("txtCreatedBy").Visible = False
e.Item.FindControl("txtCreationDate").Visible =
False
e.Item.FindControl("ddlRole").Visible = False
e.Item.FindControl("txtLocID").Visible = False
e.Item.FindControl("txtPassword").Visible = False
e.Item.FindControl("ddlUserLevel").Visible = False
e.Item.FindControl("chkActive").Visible = False
e.Item.FindControl("txtConfirmPassword").Visible =
False
e.Item.FindControl("txtCofilter").Visible = False

Case 2
e.Item.FindControl("txtCreatedBy").Visible = False
e.Item.FindControl("txtCreationDate").Visible =
False
e.Item.FindControl("txtLocID").Visible = False

e.Item.FindControl("etxtCreatedBy").Visible = False
e.Item.FindControl("etxtCreationDate").Visible =
False
e.Item.FindControl("etxtLocID").Visible = False
End Select
End If
 
O

offwhite

Have you walked through it with the debugger yet?

At a glance I do not see any reason why it would not be setting the
visibility as you want. And if possible, simply place the controls you
want to hide in a Panel and just set the Visible flag on the panel.

Also, I noticed that in your code you are assuming your controls are
always going to be found. If you do change the ID value ever this code
will break badly.

What I normally do for this code is create a useful private method...

Private Sub SetVisibility(ByVal parentControl as Control, ByVal name as
String, ByVal isVisible as bool)

Dim control as Control = parentControl.FindControl(name)
If control IsNot Nothing
control.Visible = isVisible
Else
-- Log or complain that the control was not found
End If

End Sub

You could when call it this way...

SetVisibility(e.Item, "etxtCreationDate", True)

In your log you may see that for some reason it is not finding your
controls.


Brennan Stehling
http://brennan.offwhite.net/blog/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top