Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6671613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:24:33+00:00 2026-05-26T03:24:33+00:00

I am looking for a line of code that can show how many replies

  • 0

I am looking for a line of code that can show how many replies a topic has in my forum. I have a repeater(REPEATER_1) to show other info about each topic, like it’s title and text. For example, to get the title, I use:

<%# DataBinder.Eval(Container, "DataItem.title")%>

This works fine, but for counting replies, I need to access another table, and count all replies for this topic. I use the following SelectCommand:

"SELECT COUNT(ID) FROM [replies] WHERE parent='" & <%# DataBinder.Eval(Container, "DataItem.ID")%> & "';"

But how do I execute this SelectCommand from within the Form (and within the repeater area) of the page using <%# XXXX.. %>

I know there are alternatives using code-behind, but I am practicing doing it this way using <%# XXXX.. %>

Also, what is it called when doing script inside a form using “<%# XXXX.. %>” ? It will make it easier for me to search on the web, as google or this website cannot search for “<%#”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:24:33+00:00Added an answer on May 26, 2026 at 3:24 am

    I would do this in the ItemDataBound event of the Repeater.

    I’m following your current approach, but you should return the reply count with the query that gets the topics. Doing it the way you’re doing it, you’re calling the database too many times.

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // !! use a parameterized query here to avoid SQL injection
        string query = String.Format("SELECT x FROM y WHERE z = {0}", DataBinder.Eval(e.Item.DataItem, "SomeColumn"));
    
        //execute your query to get reply count
        int replyCount = ExecuteQuery(query); // !! example
    
        Label lbl = e.Item.FindControl("ReplyCountLabel") as Label;
        if (lbl != null)
        {
            lbl.Text = replyCount.ToString()
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a simple line or two of code that will grab an
I'm looking for a small code snippet that will find a line in file
I am looking for a (preferably) command-line tool that can reformat the C# source
I'm looking for a way that I can parse command line arguments into my
I'm looking for one line code examples in various languages for getting a valid
I'm looking for Javascript code for letting the user draw a line (on an
I am looking for a Linux command-line tool that would report the disk IO
I have here a piece of code that record the number of bottles collected
So, I am working on a Linux based command line utility, that has to
I am looking at code that toggles displaying and hiding a table column. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.