hi guys,
i m displaying news titles & it's contents using repeater control.
pictorial representation:

news Title 1
news Title 2
news Title 3
news Title 4

now, when i click on news Title 1,it's content should appear from my database in between news title 1 and news title 2.same thing like accordin pane.when i click news title 2 then it's content should appear between news title and news title 3.

i m using asp.net2.0

Dani AI

Generated

Building on 's scenario and the suggestions already posted, two practical, robust options will give the accordion behavior you want: a server-side toggle (single postback per open/close) or a client-side AJAX toggle (no postback). A small progressive-enhancement pattern is best: render a normal link that points to a detail page (so non-JS users and search engines work), and use JavaScript to intercept and load inline content when JS is available.

Server-side (simple, no extra files): put a LinkButton in the Repeater and a hidden Panel/Literal for content. In ItemCommand fetch the content on demand, toggle the Panel and store the open ID in ViewState so it survives postbacks:

<ItemTemplate>
  <asp:LinkButton ID="lnkTitle" runat="server"
    CommandName="Toggle" CommandArgument='<%# Eval("News_Id") %>'>
    <%# Eval("News_Title") %>
  </asp:LinkButton>

  <asp:Panel ID="pnlContent" runat="server" Visible="false">
    <asp:Literal ID="litContent" runat="server" />
  </asp:Panel>
</ItemTemplate>

Code-behind (sketch):

protected void rpt_ItemCommand(object s, RepeaterCommandEventArgs e) {
  if (e.CommandName!="Toggle") return;
  int id = Convert.ToInt32(e.CommandArgument);
  Panel pnl = (Panel)e.Item.FindControl("pnlContent");
  Literal lit = (Literal)e.Item.FindControl("litContent");
  if (!pnl.Visible) {
    // parameterized query to load content into 'content'
    lit.Text = Server.HtmlEncode(content).Replace("\n","<br/>"); // or assign raw HTML only if sanitized
  }
  pnl.Visible = !pnl.Visible;
  ViewState["OpenNewsId"] = pnl.Visible ? id : null;
}

Client-side (AJAX, nicer UX): render an anchor with href that points to your detail page and a data-id attribute. Intercept clicks with jQuery, fetch content from a handler (ashx/aspx) using a parameterized backend query, and slideToggle the result. If JS is disabled the anchor falls back to the detail page.

Showing content on another page: with a data control use a SqlDataSource + DetailsView bound to QueryStringParameter("News_Id"). Without data controls, read Request.QueryString["News_Id"] on Page_Load, validate with int.TryParse, run a parameterized SqlCommand, and populate a Label/Literal. Always validate input, use parameters (no string concatenation), and sanitize/encode output depending on whether stored content contains HTML.

Notes: avoid re-binding the Repeater on every postback (use if (!IsPostBack) or persist the open ID), cache heavy content if needed, and be careful about XSS when rendering stored HTML.

Recommended Answers

All 5 Replies

itemTemplate :)

hi guys,
i m displaying news titles & it's contents using repeater control.
pictorial representation:

news Title 1
news Title 2
news Title 3
news Title 4

now, when i click on news Title 1,it's content should appear from my database in between news title 1 and news title 2.same thing like accordin pane.when i click news title 2 then it's content should appear between news title and news title 3.

i m using asp.net2.0

you need to set the CommandName property of your link button(news title 1 and so on) showing in repeater control. Then you need to handle the ItemCommand event of Repeater control and then pass the commandName in your select query or whatever you are using to show the content of news title in accordin panel.

you need to set the CommandName property of your link button(news title 1 and so on) showing in repeater control. Then you need to handle the ItemCommand event of Repeater control and then pass the commandName in your select query or whatever you are using to show the content of news title in accordin panel.

thanks for the sauggestion i have used repeater control and then take headertempalte n itemtemplate,in itemtemplate

       <ItemTemplate>
            <table>
            <tr>

                <td><asp:HyperLink ID="HyperLink1" navigateurl='<%# String.Format("Default.aspx?News_Id={0}", Eval("News_Id")) %>' runat="server"><%#DataBinder.EvalContainer.DataItem,"News_Title") %></asp:HyperLink></td>
            </tr>
            </table>

        </ItemTemplate>

now i got the links on the news titles.

NEXT PROBLEM:

i want to show news title and news content on other page as i have passed news_id by session shown in upper side code in itemtemplate.now how can i show records with and wthout using any data control on another web form?

thanks for the sauggestion i have used repeater control and then take headertempalte n itemtemplate,in itemtemplate
<ItemTemplate>
<table>
<tr>

<td><asp:HyperLink ID="HyperLink1" navigateurl='<%# String.Format("Default.aspx?News_Id={0}", Eval("News_Id")) %>' runat="server"><%#DataBinder.EvalContainer.DataItem,"News_Title") %></asp:HyperLink></td>
</tr>
</table>

</ItemTemplate>

now i got the links on the news titles.

NEXT PROBLEM:

i want to show news title and news content on other page as i have passed news_id by session shown in upper side code in itemtemplate.now how can i show records with and wthout using any data control on another web form?

It will be placed in Header Control. You cannot fire the header control like grid view so you have to write it by yourself.

See here for understand more.

[snipped]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.