0

I've written a code to get departments from database and put it into a list, List<CLDepartements>; which contains getters and setters. How can I display this in a HTML table? I don't want to use DataSet or GridView and I'm not using the Razor view engine.

[WebMethod]
public CLDepartements[] getAllDepartements()
{
    string chConn = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
    List<CLDepartements> depList = new List<CLDepartements>();

    using (SqlConnection conn = new SqlConnection(chConn))
    {
        string sql = @"SELECT * FROM Departement";
        conn.Open();

        using(SqlCommand cmd = new SqlCommand(sql, conn))
        {
            SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            if (rd != null)
            {
                while (rd.Read())
                {
                    var dp = new CLDepartements
                    {
                        DepID = rd.GetInt32(0),
                        DepLibelle = rd.GetString(1),
                        DepDescription = rd.GetString(2)
                    };

                    depList.Add(dp);
                }    
            }
        }

        return depList.ToArray();
    }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

Whatever code is consuming the web service just needs to iterate through the returned list and output it as rows in an HTML table.

CFL_Jeff
  • 2,589
  • 3
  • 31
  • 49