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 259721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:17:16+00:00 2026-05-11T22:17:16+00:00

I’ve created a class library which exposes my back-end object model. I don’t wish

  • 0

I’ve created a class library which exposes my back-end object model. I don’t wish to databind straight to SQL or XML, as a surprising number of tutorials/demos out there seem to assume.

In my Page_Load(), within the if (!IsPostbak), I currently set all the values of my controls from the object model, and call Databind() on each control.

I have a button event handler which deletes an item from the object model (it’s a List in this case) and rebinds it to the Repeater. First of all, this is messy – rebinding each time – but more importantly, no values are displayed when the page reloads. Should I put the databinding code outside the if statement in Page_Load()?

The second part of the question is regarding going back to basics – what’s the best way to databind in Asp.net? I’m mainly interested in binding against lists and arrays. I would have imagined there being a way to tell a control (e.g. TextBox) to databind to a string variable, and for the string to always reflect the contents of the text box, and the text box to always reflect the contents of the string. I tried the <%#…%> syntax but got no further than using the code-behind as described above.

I’ve read several overviews of databinding, but nothing out there seems to do what I want – they all talk about linking DataSets to a SQL database!

Turning to the knowledge of StackOverflow.

  • 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-11T22:17:16+00:00Added an answer on May 11, 2026 at 10:17 pm

    You’ll need to databind on every page load so you need to remove the code from within your !IsPostBack block.

    When using a list or array handle the databinding event on the control. For a repeater you’ll need to handle the ItemDataBound event.

    This example has been modified from http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx:

    <%@ Page Language="C#" AutoEventWireup="True" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html  >
     <head>
        <title>OnItemDataBound Example</title>
    <script language="C#" runat="server">
           void Page_Load(Object Sender, EventArgs e) {
                 ArrayList values = new ArrayList();
    
                 values.Add(new Evaluation("Razor Wiper Blades", "Good"));
                 values.Add(new Evaluation("Shoe-So-Soft Softening Polish", "Poor"));
                 values.Add(new Evaluation("DynaSmile Dental Fixative", "Fair"));
    
                 Repeater1.DataSource = values;
                 Repeater1.DataBind();
           }
    
           void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
    
              // This event is raised for the header, the footer, separators, and items.
    
              // Execute the following logic for Items and Alternating Items.
              if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
    
                 if (((Evaluation)e.Item.DataItem).Rating == "Good") {
                    ((Label)e.Item.FindControl("RatingLabel")).Text= "<b>***Good***</b>";
                 }
              }
           }    
    
           public class Evaluation {
    
              private string productid;
              private string rating;
    
              public Evaluation(string productid, string rating) {
                 this.productid = productid;
                 this.rating = rating;
              }
    
              public string ProductID {
                 get {
                    return productid;
                 }
              }
    
              public string Rating {
                 get {
                    return rating;
                 }
              }
           }
    
        </script>
    
     </head>
     <body>
    
        <h3>OnItemDataBound Example</h3>
    
        <form id="form1" runat="server">
    
           <br />
           <asp:Repeater id="Repeater1" OnItemDataBound="R1_ItemDataBound" runat="server">
              <HeaderTemplate>
                 <table border="1">
                    <tr>
                       <td><b>Product</b></td>
                       <td><b>Consumer Rating</b></td>
                    </tr>
              </HeaderTemplate>
    
              <ItemTemplate>
                 <tr>
                    <td> <asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "ProductID") %>' Runat="server"/> </td>
                    <td> <asp:Label id="RatingLabel" Text='<%# DataBinder.Eval(Container.DataItem, "Rating") %>' Runat="server"/> </td>
                 </tr>
              </ItemTemplate>
    
              <FooterTemplate>
                 </table>
              </FooterTemplate>
    
           </asp:Repeater>
           <br />
    
        </form>
     </body>
     </html>
    

    EDIT:
    In addition, (and you may already be aware of this) you’ll need to persist your list/array somehow. You can go all the way back to the database and reconstitute the list there or you can store it in memory with cache, viewstate, or session as viable options depending on your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try the SqlDependency class. It will fire an OnChange event… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer array_flip() exchanges all keys with their associated values in an… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer You are disposing the ServiceHost instance as soon as you… May 11, 2026 at 11:40 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.