articles

Home / DeveloperSection / Articles / DataRepeater Control in C#.Net

DataRepeater Control in C#.Net

Pushpendra Singh40165 24-Jan-2011

The DataRepeater control allows you to display rows of your data in a scrollable container giving you more flexibility and customization than standard grid controls.

How to use DataRepeater

Drag and drop DataRepeater control from toolbox on the window form.

DataRepeater Control in C#.Net

Drag and drop textbox in the DataRepeater Control to display data.

DataRepeater Control in C#.Net

BindData in DataRepeater

Code:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class frmDataRepeater : Form
    {
        public frmDataRepeater()
        {
            InitializeComponent();
        }
 
    private void frmDataRepeater_Load(object sender, EventArgs e)
        {
            //Connect to the Database
       string constring = "Server=(local);Database=my; User Id=sa; Password=sa";
            SqlConnection sqlcon = new SqlConnection(constring);
            //Open the connection
            sqlcon.Open();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            // Write the query
            cmd.CommandText = "select * from regform";
            da.SelectCommand = cmd;
            cmd.Connection = sqlcon;
            da.SelectCommand = cmd;
            //create a dataset
            DataSet ds = new DataSet();
            da.Fill(ds);
            //Close the connection
            sqlcon.Close();
            // Bind data to TextBox
            textBox1.DataBindings.Add("Text", da, "id");
            textBox2.DataBindings.Add("Text", da, "pass");
            textBox3.DataBindings.Add("Text", da, "name");
            dataRepeater1.Visible = true;
            dataRepeater1.DataSource = ds.Tables[0];
        }
    }
}

 

Data will bind to the DataRepeater when application run.

Run the project

DataRepeater Control in C#.Net

You can see next data by making scroll bar down.

 

DataRepeater Control in C#.Net


Updated 23-Aug-2020

Leave Comment

Comments

Liked By