How to make a hyperlink Visible or not visible in DataList

  • Thread starter Patrick Olurotimi Ige
  • Start date

P

Patrick Olurotimi Ige

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?
 
Ad

Advertisements

P

Patrick Olurotimi Ige

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

Eliyahu Goldin

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

Eliyahu
 
P

Patrick Olurotimi Ige

I want to hide the hyperlink before the user clicks the checkbox then
make it enable after the user clicks the checkbox.
 
E

Eliyahu Goldin

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
 
E

Eliyahu Goldin

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
 
Ad

Advertisements

G

Guest

Eliyahu Goldin said:
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

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
 
Ad

Advertisements

P

Patrick Olurotimi Ige

Thanks Jouni Karppinen for the info.
I will try that approach too.
Patrick
 

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

Top