How to bind repeater from two tables in

Bind multiple tables to one repeater.

I have a simple solution:

I have two tables Users & Services and my repeater has fields from the two tables.

First create repeater like this.

<asp:Repeater ID="rpServices" runat="server">
<td><%# Eval("photo_user")%></td>
<td><%# Eval("name_user")%></td>
<td><%# Eval("Service_Name")%></td>
<td><%# Eval("Field_service")%></td>
<td><%# Eval("Cost_service")%></td>

Then Create a method for repeater fill up.

private void RepeaterBind()
string connectionString = "Data Source=sandeepss-PC;Initial Catalog=CodeFirst;User ID=sa; Password=knowdev";
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(@"Select u.photo_user,u.name_user,
s.Cost_service FROM Users as u inner join Services as s on u.userId=s.userId", cn);
IDataReader dr = cmd.ExecuteReader();

DataTable dt = new DataTable();
rpServices.DataSource = dt;


Finally Call this method where you filling repeater control.

For example I am calling it on Page_Load.

protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)

About the Author