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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:19:45+00:00 2026-05-11T16:19:45+00:00

What is the right way to implement DataBind() method for control which have a

  • 0

What is the right way to implement DataBind() method for control which have a repeater inside of it?

These are requirements for this control (but you can offer yours if think these are missing of something or are an overhead)

  • Control should accept a collection or an enumerable (list of objects, anonymous objects, dictionaries or data table)
  • DataSource should be completely should be completely decoupled from the control (using Data*Field properties to specify properties or keys mapped; like DataValueField and DataTextField in DropDownList)
  • The control should go easy on ViewState. If possible ViewState shouldn’t be used at all, or it’s usage should be as low as possible (store some ID or something like this)
  • The control should handle any type (converting it using ToString())
  • Inside of ItemDataBound be able to use e.DataItem should be accessible if possible

I want my control to be initialized like so:

var control = new Control();
control.DataDateField = "Date";
control.DataNameField = "FullName";
control.DataTextField = "Comment";
control.DataSource = data;
control.DataBind();

And data item can be one of the following

List of dictionaries (or table rows)

var data = new List<Dictionary<string, string>>
{
    new Dictionary<string, string>
        {{"Date", "2009-03-15"}, {"FullName", "John Walker"}, {"Comment", "comment1"}},
    new Dictionary<string, string>
        {{"Date", "2009-03-12"}, {"FullName", "Chuck Norris"}, {"Comment", "comment2"}},
    new Dictionary<string, string>
        {{"Date", "2009-03-13"}, {"FullName", "Sergej Andrejev"}, {"Comment", "comment3"}}
};

List of anonymous objects

var data = new List<object>
{
    new {Date = "2009-03-15", FullName = "John Walker", Comment = "comment1"},
    new {Date = "2009-03-12", FullName = "Chuck Norris", Comment = "comment2"},
    new {Date = "2009-03-13", FullName = "Sergej Andrejev", Comment = "comment3"},
};

List of ojects

public class SampleClass
{
    public object Date { get; set; }
    public object FullName { get; set; }
    public object Comment { get; set; }

    public SampleClass(string date, string fullName, string comment)
    {
        Date = date;
        FullName = fullName;
        Comment = comment;
    }
};

var data = new List<SampleClass>
{
    new SampleClass("2009-03-15", "John Walker", "comment1"),
    new SampleClass("2009-03-12", "Chuck Norris", "comment2"),
    new SampleClass("2009-03-13", "Sergej Andrejev", "comment3"),
};

DataTable

var data = new DataTable();
data.Columns.Add(new DataColumn { DataType = typeof(DateTime), ColumnName = "Date" });
data.Columns.Add(new DataColumn { DataType = typeof(string), ColumnName = "FullName" });
data.Columns.Add(new DataColumn { DataType = typeof(string), ColumnName = "Comment" });

data.Rows.Add(new object[] { DateTime.Parse("2009-03-15"), "John Walker", "comment1" });
data.Rows.Add(new object[] { DateTime.Parse("2009-03-12"), "Chuck Norris", "comment2" });
data.Rows.Add(new object[] { DateTime.Parse("2009-03-13"), "Sergej Andrejev", "comment3" });

Basically what I want is universal code for data binding so I wouldn’t waste time creating it from scratch every time I create new control. I would appreciate any references to good practices, official guides and of course your personal experience.

  • 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-11T16:19:45+00:00Added an answer on May 11, 2026 at 4:19 pm

    This article works up an example databound control with templating:

    Building DataBound Templated Custom ASP.NET Server Controls

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

Sidebar

Ask A Question

Stats

  • Questions 87k
  • Answers 87k
  • 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 Yes, jquery will care about that. but always add the… May 11, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer In Python 3.0.1, I have gotten that error after I… May 11, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer As luke noted, the code to create and bind the… May 11, 2026 at 5:30 pm

Related Questions

I want to implement index feature in UITableView as is in the standart contacts
Inspired by a recent TED talk , I want to write a small piece
I would like to implement the method User.calculate_hashed_password . I'm trying to use the
I'm very new to both the Mvc framework as well as JavaScript and JQuery.
I'm writing a GUI application that will have a user log in feature. Each

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.