Show and Hide

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I created an Asp:Repeater where I have an Asp:Panel and an Asp:Label.
In each record of the repeater I want to have a small button which
hides or shows the panel in that record. If possible with no postback.

And it would be great to have a button like "Show" which would change
to "Hide".
Well, but this is not so important.

Could somebody, please, help me out with this? I have no idea of how to
create this.

Thanks,
Miguel
 
hi

You can use javascript to hide/show the panel inside the repeater.

Create Javascritp function to hide or show panel

function show_hide(pnl, btn)
{
document.getElementById(pnl).style.display =
document.getElementById(pnl).style.display == "none" ? "block" :
"none";

if (document.getElementById(pnl).style.display=="block")
document.getElementById(pnl).caption="Hide";
else
document.getElementById(pnl).caption="Show";
}

now you can call these function on click event of button, to do that
you have bind to fucntion to button control on ItemCreated Event of
Reapeate. following is the code for that.

Private Sub Repeater1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemCreated

Dim rtpItem As ListItemType
Dim pnl As HtmlGenericControl
Dim btn As Button
rtpItem = ListItemType.Item
If rtpItem = ListItemType.AlternatingItem Or rtpItem =
ListItemType.Item Then
pnl = CType(e.Item.FindControl("pnl"), HtmlGenericControl)
btn = CType(e.Item.FindControl("btn"), Button)
btn.Attributes.Add("onclick", "show_hide('" & pnl.ClientID
& "','" & btn.ClientID & "');")
End If

End Sub

Note to get the panel control using e.Item.FindControl("pnl") you must
have to make the html panel a server control it means you have to write
runat="server" in html tag of panel control. otherwise you will get
error like control with name pnl not found.
 
Back
Top