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

  • Home
  • SEARCH
  • 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 6350095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:44:54+00:00 2026-05-24T21:44:54+00:00

I want to use asp.net repeater control to display all threads that under same

  • 0

I want to use asp.net repeater control to display all threads that under same topic. Each thread has three buttons–reply,edit and delete. Besides buttons, I also want to display author, subject, post time and content. I have two questions here regarding to how to write button click event and binding data to a div in backend. My front end code is as following:(I use c#)

<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td colspan="2">
                <asp:Button ID="btn_Reply" runat="server" Text="Rreply"     OnClick="btn_Reply_Click" />
                <asp:Button ID="btn_Edit" runat="server" Text="Edit" OnClick="btn_Edit_Click" CommandArgument='<%Eval("id").ToString() %>' />
                <asp:Button ID="btn_Delete" runat="server" Text="Delete" OnClick="btn_Delete_Click" CommandArgument='<%Eval("id").ToString() %>' />
            </td>
       </tr>
       <tr>
            <td align="right" width="100px">Author:</td>
            <td><%#Eval("owner") %></td>
       </tr>
       <tr>
            <td align="right" width="100px">Subject:</td>
            <td><%#Eval("title") %></td>
       </tr>
       <tr>
            <td align="right" width="100px">Post Time:</td>
            <td><%#Eval("timePosted") %></td>
       </tr>
       <tr>
            <td colspan="2">
                <div id="contentDiv" runat="server" ondatabinding="contentDiv_DataBinding"></div>
            </td>
       </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
    </asp:Repeater>

Question 1: how to write button click event in backend, for example I want to use CommandArgument of edit button, what’s the click event should be?
protected void btn_Edit_Click(object sender,??//I don’t know how to write the second)

Question 2: the content stored in database is in html format, What to write in contentDiv_DataBinding event?

 protected void contentDiv_DataBinding(object sender, System.EventArgs e)
    {
         //seems it can not find contentDiv, otherwise, I'll just use contentDiv.html=<%#Eval("content") %>
    }

Thank you in advance!

  • 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-24T21:44:55+00:00Added an answer on May 24, 2026 at 9:44 pm

    As the control is nested inside the Repeater, you must refer to it by finding it inside the item being data bound:

     protected void Repeater_DataBinding(object sender, System.EventArgs e)
        {
             HtmlControl contentDiv = e.item.FindControl("contentDiv");
        }
    

    However, I think it would be better to put a Literal control inside the Div and refer to that instead:

    <div id="contentDiv" runat="server">
       <asp:literal id="ltlContent" runat="server" />
    </div>
    
     protected void Repeater_DataBinding(object sender, System.EventArgs e)
        {
             Literal ltlContent = e.item.FindControl("ltlContent");
             ltlContent = e.Item.DataItem("content");
        }
    

    Regarding controlling the buttons inside the Repeater, you can add a CommandName to the button and call this in the ItemCommand event:

    <asp:Button ID="btn_Reply" runat="server" Text="Rreply" CommandName="Reply" CommandArgument='<%Eval("id")%>' />
    <asp:Button ID="btn_Edit" runat="server" Text="Edit" CommandName="Edit" CommandArgument='<%Eval("id").ToString() %>' />
    <asp:Button ID="btn_Delete" runat="server" Text="Delete" CommandName="Delete" CommandArgument='<%Eval("id").ToString() %>' />
    
     protected void contentDiv_ItemCommand(object sender, System.EventArgs e)
        {
             if (e.CommandName == "Reply"){
    
             }
             if (e.CommandName == "Edit"){
    
             }
             if (e.CommandName == "Delete"){
    
             }
        }
    

    Finally, change your Repeater tag to:

    <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater_DataBinding" OnItemCommand="contentDiv_ItemCommand">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net user control on which I want to use jquery ajax.
If I want to use ASP.Net without the Microsoft AJAX Control Toolkit or JQuery
I have an ASP.Net Repeater I want to use to show From and Text
I dont want to use asp.net's TreeView control. I want to create a custom
I use repeater in my asp.net application to display records from database. The datasource
I want to use ASP.NET and IIS to download dynamically generated files to the
I want to use ASP.Net on Linux because of license problems and costs. Can
In my Asp.net MVC 1.0 application I want to use CKEditor as my Rich
I want to use forms authentication in my asp.net mvc site. Can I use
I want to use an IFrame in my ASP.Net MVC application, yet I want

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.