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?


    *** Sent via Developersdex http://www.developersdex.com ***
    Patrick Olurotimi Ige, Jun 14, 2005
    #1
    1. Advertising

  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!!


    *** Sent via Developersdex http://www.developersdex.com ***
    Patrick Olurotimi Ige, Jun 14, 2005
    #2
    1. Advertising

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

    Eliyahu

    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    > 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?
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    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.


    *** Sent via Developersdex http://www.developersdex.com ***
    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

    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    > 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!!
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    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

    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    > I want to hide the hyperlink before the user clicks the checkbox then
    > make it enable after the user clicks the checkbox.
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    Eliyahu Goldin, Jun 14, 2005
    #6
  7. "Eliyahu Goldin" wrote:

    > 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
    >
    > "Patrick Olurotimi Ige" <> wrote in message
    > news:...
    > > I want to hide the hyperlink before the user clicks the checkbox then
    > > make it enable after the user clicks the checkbox.
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***

    >


    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
    =?Utf-8?B?Sm91bmkgS2FycHBpbmVu?=, Jun 15, 2005
    #7
  8. Patrick Olurotimi Ige, Jun 15, 2005
    #8
    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. spamfurnace
    Replies:
    1
    Views:
    2,624
    Scott M.
    May 24, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,846
  3. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,426
    Brian Hoops
    Oct 28, 2004
  4. keithb
    Replies:
    4
    Views:
    7,708
    starsky163
    Oct 17, 2008
  5. Jurjen de Groot
    Replies:
    0
    Views:
    293
    Jurjen de Groot
    May 19, 2008
Loading...

Share This Page