Hide / Show Panels through a Repeater

S

Sully

Hi Everyone,

I am pretty new to coding in .net and need some help in showing and
hiding information from a repeater control. I am calling a list of
FAQ's from a Database and display both the question and answer. What i
would like to happen is to display the list of questions and when the
user clicks on one of them, the answer appears below.

There are about 50 or so FAQ's, so I don't really want to use the
Javascript of Show/Hide div's as was previously used. And these FAQ's
appear on about 7 sites, so I am trying to save myself from coding
several different pages for one FAQ change. What I have so in my code
behind is:
SqlConnection myConnection = new
SqlConnection("server=IP;uid=user;pwd=password;database=value");
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * from FAQ",
myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds);
rptQuestions.DataSource = ds;
rptQuestions.DataBind();

and my repeater is simply inserted as:
<asp:Repeater ID="rptQuestions" runat="server">
<ItemTemplate>
<p><b><%# DataBinder.Eval(Container.DataItem, "FAQ_Question") %></b><br
/>
<%# DataBinder.Eval(Container.DataItem, "FAQ_Answer") %></p><br />
</ItemTemplate>
</asp:Repeater>

All this does is just display the questions and answers in paragraph
format. Any help would be appreciated.

THANKS!
 
T

Tasos Vogiatzoglou

<asp:Repeater ID="rptQuestions" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
<b><%# DataBinder.Eval(Container.DataItem, "FAQ_Question")></b>
</td>
<td><a href="#" onclick="toggleQuestion('<%#
DataBinder.Eval(Container.DataItem, "FAQ_ID")>')">Show answer</a></td>
</tr>
<tr><td colspan="2">
<div style="display:none" id='<%# DataBinder.Eval(Container.DataItem,
"FAQ_ID")>'><%# DataBinder.Eval(Container.DataItem, "FAQ_Answer") %>
</div>
</td></tr>
</table>
</ItemTemplate>
</asp:Repeater>

<script>
function toggleQuestion(id) {
var elem = document.getElementById(id);
elem.styles.display = elem.styles.display=="none"?"block":"none";
}
</script>

Regars,
Tasos
 

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