title: how to show data in datalist from database in asp.net
body: <p>i have three tables 1)Manager, 2)Teamleader, 3)Agent.
  i want to show how many agent are in particular manager, like i have shown in image, natasha,odeya are in under ben and Emma is under Jonny but both are under john. i want to show these agents list in datalist</p>
  
  <p><a href="https://i.stack.imgur.com/thzls.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/thzls.jpg" alt="enter image description here"></a></p>
  
  <p>i use this code:</p>
  
  <pre><code>string agent = Session["UserEmail"].ToString();
  ArrayList Course = new ArrayList();
  string query = "select Email_ID from tblTeamLeaders where IsActive_By='" + agent + "'";
  using (SqlCommand cm = new SqlCommand(query, conn))
  {
      conn.Open();
      SqlDataReader reader = cm.ExecuteReader();
      while (reader.Read())
      {
          Course.Add(reader.GetString(0));
      }
      conn.Close();
  }
  foreach (string value in Course)
  {
      conn.Open();
      string str = "select DISTINCT name from [tblAgents] where IsActive='True' and IsActive_By='" + value + "'";
      SqlCommand cmd = new SqlCommand(str, conn);
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      da.Fill(ds);
      DataList1.DataSource = ds;
      DataList1.DataBind();
      conn.Close();
  }
  </code></pre>