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

Discussion in 'ASP .Net Web Controls' started by Dgreer, Aug 31, 2006.

  1. Dgreer

    Dgreer Guest

    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
     
    Dgreer, Aug 31, 2006
    #1
    1. Advertising

  2. Dgreer

    Guest

    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/


    Dgreer wrote:
    > 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
     
    , Sep 1, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rathtap
    Replies:
    0
    Views:
    427
    Rathtap
    Jun 23, 2004
  2. Ken McCrory

    Change Labels to Textboxes easily?

    Ken McCrory, Mar 9, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    395
  3. Angel.Net
    Replies:
    1
    Views:
    367
    =?Utf-8?B?Q3JhaWc=?=
    Jun 15, 2005
  4. Replies:
    1
    Views:
    472
  5. Eagle

    Sizing of DropDownLists and textboxes in a grid

    Eagle, May 11, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    140
    Eagle
    May 11, 2005
Loading...

Share This Page