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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:39:35+00:00 2026-05-21T12:39:35+00:00

I have a repeater defined as <asp:Repeater id=rep1 runat=server> <ItemTemplate> <%#Eval(name)%> </ItemTemplate> </asp:Repeater> The

  • 0

I have a repeater defined as

<asp:Repeater id="rep1" runat="server">
<ItemTemplate>
<%#Eval("name")%>
</ItemTemplate>
</asp:Repeater>

The code behind is as

 try
        {
            SqlConnection xconn = new SqlConnection();
            xconn.ConnectionString = @"Data Source=XXXXXX;Trusted_Connection=yes;database=master";
            xconn.Open();
            lbl1.Text = "Connected to SQL";
            SqlCommand ycmd = new SqlCommand("select * from student",xconn);
            SqlDataReader dr = ycmd.ExecuteReader();
            cdcatalog.DataSource = dr;
            cdcatalog.DataBind();
        }
        catch (Exception)
        {
            lbl1.Text= "Cannot connect to SQL";
        }

Why does it not bind the data in the repeater?

  • 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-21T12:39:36+00:00Added an answer on May 21, 2026 at 12:39 pm

    Why are you binding data readers to a repeater? I would recommend you using strongly typed objects. So start by defining a model that will represent your data:

    public class Student
    {
        public string Name { get; set; }
    }
    

    then a method to fetch those students:

    public IEnumerable<Student> GetStudents()
    {
        using (var conn = new SqlConnection("Data Source=XXXXXX;Trusted_Connection=yes;database=master"))
        using (var cmd = conn.CreateCommand())
        {
            conn.Open();
            cmd.CommandText = "SELECT Name FROM Students;";
            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    yield return new Student
                    {
                        Name = reader.GetString(reader.GetOrdinal("Name"));
                    }
                }
            }
        }
    }
    

    and then bind the repeater:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rep1.DataSource = GetStudents().ToArray();
            rep1.DataBind();
        }
    }
    

    and in the view:

    <asp:Repeater id="rep1" runat="server">
        <ItemTemplate>
            <%# Eval("Name") %>
        </ItemTemplate>
    </asp:Repeater>
    

    Also note that the name of the repeater is rep1 so that’s what you should use in your code behind.

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

Sidebar

Related Questions

I have two nested repeaters in my *.aspx page. <asp:Repeater runat=server id=rptMain> <ItemTemplate> <h1><%#DataBinder.Eval(Container.DataItem,
I have a repeater like this: <asp:Repeater runat=server ID=pde> <HeaderTemplate></HeaderTemplate> <ItemTemplate> <asp:Literal runat=server ID=literal1></asp:Literal>
I have a Repeater control in my aspx page: <asp:Repeater ID=repeater runat=server EnableViewState=false> <ItemTemplate>
I have repeater with item template: <asp:Repeater ID=queryParametersRepeater runat=server DataSourceID=queryParametersObjectDataSource> <ItemTemplate> <tr class=itemTemplate> <td
I have Repeater Control and in that i have code like this <div runat=server
I have Repeater Control as shown below. <asp:Repeater ID=rptCategory runat=server> <HeaderTemplate> <h2 class=art-logo-text style=margin-bottom:
Take following example of code: (ASP.NET WebForms) <asp:Content ContentPlaceHolderID=Contents runat=server> <div class=blogpost-list> <asp:Repeater ID=blogList
I have a repeater control that contains an ItemTemplate containing a databound label and
I have below piece of code in my actionscript file (defined in a function)
Lets say I have defined a class in my CSS, with the class name

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.