How to make a hyperlink Visible or not visible in DataList

Discussion in 'ASP .Net' started by Patrick Olurotimi Ige, Jun 14, 2005.

  1. I have a Datalist in a form
    with a hyperlink i would like to make the hyperlink visible only when a
    checkbox is clicked and not visible when not clicked .

    But doing this below in page_load it gives me error:-
    Object reference not set to an instance of an object.


    If CheckBox1.Checked = True Then
    hyperlink1.Visible = True
    End If

    What am i doing wrong?
     
    Patrick Olurotimi Ige, Jun 14, 2005
    #1
    1. Advertisements

  2. Thx Eliyahu for the reply.
    I also enabled AutoPostBack = true in the checkBox.

    But i tried
    Public Sub ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataListItemEventArgs)

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

    If CType(e.Item.FindControl("CheckBox1"), CheckBox).Checked
    Then


    hyperlink1.Visible = True

    End If

    End If


    But it doesn't work!!
     
    Patrick Olurotimi Ige, Jun 14, 2005
    #2
    1. Advertisements

  3. Probably you have both the hyperlink and the checkbox in an itemtemplate.
    Items are built in ItemDataBound event. Put your code there.

    Eliyahu
     
    Eliyahu Goldin, Jun 14, 2005
    #3
  4. I want to hide the hyperlink before the user clicks the checkbox then
    make it enable after the user clicks the checkbox.
     
    Patrick Olurotimi Ige, Jun 14, 2005
    #4
  5. One second. What exactly do you want to achieve? Do you want to hide the
    hyperlink when the users clicks the checkbox or you want to hide the
    hyperlink when the checkbox is set checked in the process of databinding?

    Eliyahu
     
    Eliyahu Goldin, Jun 14, 2005
    #5
  6. If the link needs to be always hidden when the page loads, you don't need to
    handle ItemDataBound. You need to handle either the checkbox's
    OnCheckedChanged event or the DataList's ItemCommand event.

    Eliyahu
     
    Eliyahu Goldin, Jun 14, 2005
    #6
  7. Patrick Olurotimi Ige

    Guest Guest

    You could also try using Client side Javascript.

    Hide all hyperlinks by using css and "display:none".

    Then create javascript function which handles changing hyperlinks visibility
    by setting "display:'' or "display:none"

    Finally add client side eventhandler to all checkboxes by using
    checkbox1.Attributes.Add method.

    Most difficult part will be creating that JavaScript which finds right
    hyperlink to show.
    (If I understood right and you have one hyperlink on each datalist row)


    http://authors.aspalliance.com/das/datagriddblclick.aspx
     
    Guest, Jun 15, 2005
    #7
  8. Thanks Jouni Karppinen for the info.
    I will try that approach too.
    Patrick
     
    Patrick Olurotimi Ige, Jun 15, 2005
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.