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.
Drag and drop textbox in the DataRepeater Control to display data.
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
You can see next data by making scroll bar down.
priya R
05-Aug-2011priya R
05-Aug-2011