title: How to bind repeater in asp.net using for loop?
body: <pre><code>String CS = ConfigurationManager.ConnectionStrings[&quot;MyDatabaseConnectionString&quot;].ConnectionString;
  
  using (SqlConnection con = new SqlConnection(CS))
  {
      using (SqlCommand cmd = new SqlCommand(&quot;Select FriendTable.UserId from FriendTable inner join UserTable on UserTable.Id = FriendTable.FriendId Where FriendTable.FriendId='&quot; + Session[&quot;ID&quot;].ToString() + &quot;' And FriendTable.Status='Request'&quot;, con))
      {
          using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
          {
               DataTable dt = new DataTable();
               DataSet ds = new DataSet();
               sda.Fill(ds, &quot;FriendTable.UserId&quot;);
              
               foreach (RepeaterItem item in rptrRequest.Items)
               {
                   int i = 0;
  
                   for (i = 0; i &lt;= ds.Tables[0].Rows.Count - 1; i++)
                   {
                       SqlCommand cmmd = new SqlCommand(&quot;Select * From UserTable Where Id='&quot; + ds.Tables[0].Rows[i][&quot;UserId&quot;].ToString() + &quot;'&quot;, con);
                       SqlDataAdapter sdap = new SqlDataAdapter(cmmd);
                       DataTable dtBrands = new DataTable();
                       sdap.Fill(dtBrands);
                       rptrRequest.DataSource = dtBrands;
                       rptrRequest.DataBind();
                   }
               }
          }
      }
  }
  </code></pre>